daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Apr 25th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Copyright(c) 2015, Konrad K Sobon
  2. # @arch_laboratory, http://archi-lab.net
  3.  
  4. import clr
  5. clr.AddReference('ProtoGeometry')
  6. from Autodesk.DesignScript.Geometry import *
  7.  
  8. # Import Element wrapper extension methods
  9. clr.AddReference("RevitNodes")
  10. import Revit
  11. clr.ImportExtensions(Revit.Elements)
  12.  
  13. # Import geometry conversion extension methods
  14. clr.ImportExtensions(Revit.GeometryConversion)
  15.  
  16. # Import DocumentManager and TransactionManager
  17. clr.AddReference("RevitServices")
  18. import RevitServices
  19. from RevitServices.Persistence import DocumentManager
  20. from RevitServices.Transactions import TransactionManager
  21.  
  22. doc = DocumentManager.Instance.CurrentDBDocument
  23. uiapp = DocumentManager.Instance.CurrentUIApplication
  24. app = uiapp.Application
  25.  
  26. # Import RevitAPI
  27. clr.AddReference("RevitAPI")
  28. import Autodesk
  29. from Autodesk.Revit.DB import *
  30.  
  31. import sys
  32. pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
  33. sys.path.append(pyt_path)
  34. import System
  35.  
  36. #The inputs to this node will be stored as a list in the IN variable.
  37. dataEnteringNode = IN
  38.  
  39. sheets = IN[0]
  40. pRange = System.Enum.Parse(Autodesk.Revit.DB.PrintRange, IN[1])
  41. combined = IN[2]
  42. printerName = IN[3]
  43. printSetting = IN[4]
  44. filePath = IN[5]
  45. runIt = IN[6]
  46.  
  47. if isinstance(sheets, list):
  48.     viewSheets = []
  49.     for i in sheets:
  50.         viewSheets.append(UnwrapElement(i))
  51. else:
  52.     viewSheets = UnwrapElement(sheets)
  53.  
  54. def PrintView(doc, sheet, pRange, printerName, combined, filePath, printSetting):
  55.     # create view set
  56.     viewSet = ViewSet()
  57.     viewSet.Insert(sheet)
  58.     # determine print range
  59.     printManager = doc.PrintManager
  60.     printManager.PrintRange = pRange
  61.     printManager.Apply()
  62.     # make new view set current
  63.     viewSheetSetting = printManager.ViewSheetSetting
  64.     viewSheetSetting.CurrentViewSheetSet.Views = viewSet
  65.     # set printer
  66.     printManager.SelectNewPrintDriver(printerName)
  67.     printManager.Apply()
  68.     # set combined and print to file
  69.     if printManager.IsVirtual:
  70.         printManager.CombinedFile = combined
  71.         printManager.Apply()
  72.         printManager.PrintToFile = True
  73.         printManager.Apply()
  74.     else:
  75.         printManager.CombinedFile = combined
  76.         printManager.Apply()
  77.         printManager.PrintToFile = False
  78.         printManager.Apply()
  79.     # set file path
  80.     printManager.PrintToFileName = filePath
  81.     printManager.Apply()
  82.     # apply print setting
  83.     try:
  84.         printSetup = printManager.PrintSetup
  85.         printSetup.CurrentPrintSetting = printSetting
  86.         printManager.Apply()
  87.     except:
  88.         pass
  89.     # save settings and submit print
  90.     TransactionManager.Instance.EnsureInTransaction(doc)
  91.     viewSheetSetting.SaveAs("tempSetName")
  92.     printManager.Apply()
  93.     printManager.SubmitPrint()
  94.     viewSheetSetting.Delete()
  95.     TransactionManager.Instance.TransactionTaskDone()
  96.    
  97.     return True
  98.  
  99. try:
  100.     viewSets = FilteredElementCollector(doc).OfClass(ViewSheetSet)
  101.     for i in viewSets:
  102.         if i.Name == "tempSetName":
  103.             TransactionManager.Instance.EnsureInTransaction(doc)
  104.             doc.Delete(i.Id)
  105.             TransactionManager.Instance.ForceCloseTransaction()
  106.         else:
  107.             continue
  108.        
  109.     errorReport = None
  110.     message = "Success"
  111.     if runIt:
  112.         if isinstance(viewSheets, list) and isinstance(printSetting, list):
  113.             for i, j in zip(viewSheets, printSetting):
  114.                 PrintView(doc, i, pRange, printerName, combined, filePath, j)
  115.         elif isinstance(viewSheets, list) and not isinstance(printSetting, list):
  116.             for i in viewSheets:
  117.                 PrintView(doc, i, pRange, printerName, combined, filePath, printSetting)
  118.         elif not isinstance(viewSheets, list) and not isinstance(printSetting, list):
  119.             PrintView(doc, viewSheets, pRange, printerName, combined, filePath, printSetting)
  120.     else:
  121.         message = "Set RunIt to True"
  122. except:
  123.     # if error accurs anywhere in the process catch it
  124.     import traceback
  125.     errorReport = traceback.format_exc()
  126.    
  127. #Assign your output to the OUT variable
  128. if errorReport == None:
  129.     OUT = message
  130. else:
  131.     OUT = errorReport
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top