OK, here's how this works:
- First input is a Folder Path that you want to export the DWG to. Use Directory Path node for this.
- Then you have a list of views to export. For the sake of this example I just grabbed a few of the sections from my model.
- Then you have to specify a name for each exported view. That can be automated and we can let Revit automatically assign a name for each DWG but I usually want to specify my own so this is how I set this up.
- lastly we don't want to export DWG every time something changes so I added a boolean toggle to only export when its set to True. This way you can better control when this time consuming operation happens.
Code itself that was used is really simple:
# Copyright(c) 2016, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net
# Import Element wrapper extension methods
# Import DocumentManager and TransactionManager
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import RevitAPI
from Autodesk.Revit.DB import *
from System.Collections.Generic import *
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
def ProcessList(_func, _list):
return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )
def ProcessParallelLists(_func, *lists):
return map( lambda *xs: ProcessParallelLists(_func, *xs) if all(type(x) is list for x in xs) else _func(*xs), *lists )
folderPath = IN
if isinstance(IN, list):
views = ProcessList(Unwrap, IN)
views = list(Unwrap(IN))
if isinstance(IN, list):
names = IN
names = list(IN)
RunIt = IN
def ExportDwg(name, view, folder = folderPath):
options = DWGExportOptions()
views = List[ElementId]()
result = doc.Export(folder, name, views, options)
errorReport = None
# run export
ProcessParallelLists(ExportDwg, names, views)
# if error accurs anywhere in the process catch it
errorReport = traceback.format_exc()
errorReport = "Please set the RunIt to True!"
#Assign your output to the OUT variable
if errorReport == None:
OUT = 0
OUT = errorReport
Couple of things that I am doing in code here to make your life easier:
- I make sure that views and view names inputs can be either a single item or a list. They can also be a nested list so basically as long as those two have matching structure they will all get processed properly. I use the ProcessList() and Unwrap() methods for that. Have a look at those to learn some Python. It will come handy.
- Once all of the inputs are ready and processed we can just call ProcessParallelLists() to export each DWG. I basically call the method on each provided View. I know that's slower than calling it once on a viewSet but it allows me to custom name each DWG. I like that flexibility.
Ps. Get All Views node comes from Archi-lab_Grimshaw package.