Export Revit Sheets to DWG with DWG Export Settings

Hi all,

Currently working on a graph for exporting Sheets from Revit to DWG. The idea is to have a graph to Batch plot a set of Sheets with a selected set of Company defined DWG Export Options.

The graph is fairly simple at the moment and is just trying to Export one sheet.

The exact Code can be found in this Forum post: http://architects-desktop.blogspot.com/2018/12/dynamo-export-views-and-sheets-from.html

The above article also contains links to Forum threads found here which are the Basis for the Code.

As I’m fairly new to Dynamo (and python for that matter) I’m finding it difficult to Troubleshoot the issue. I can get the graph to work without trying to call Export DWG Settings which would lead me to believe that the issue is with the Settings lines of Code. Does anyone know if the Code in the python node call the Revit API correctly?

Any and all ideas are much appreciated!

P.S. First time poster here so appologies if i have missed anything! Also as a first time poster I can’t upload the Dynamo file so I’ve pasted the python node Code below

Python node Contents:

# Copyright(c) 2016, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

# Import Element wrapper extension methods
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import System
from System.Collections.Generic import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#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 )

def Unwrap(item):
return UnwrapElement(item)

folderPath = IN[0]



if isinstance(IN[1], list):
    views = ProcessList(Unwrap, IN[1])
    else:
    views = list(Unwrap(IN[1]))

if isinstance(IN[2], list):
names = IN[2]
else:
names = list(IN[2])

dwg_opt = IN[3]

RunIt = IN[5]

def ExportDwg(name, view, folder = folderPath):

options = None
settings = FilteredElementCollector(doc).WherePasses(ElementClassFilter(ExportDWGSettings))
for element in settings:
	if element.Name == dwg_opt:
		options = element.GetDWGExportOptions()
		break 
		
if options is None:
	options = DWGExportOptions()
	
options.MergedViews = IN[4]
views = List[ElementId]()
views.Add(view.Id)
result = doc.Export(folder, name, views, options)
return result

if RunIt:
try:
	errorReport = None
	# run export
	ProcessParallelLists(ExportDwg, names, views)
	
except:
	# if error accurs anywhere in the process catch it
	import traceback
	errorReport = traceback.format_exc()
else:
errorReport = "Please set the RunIt to True!"

#Assign your output to the OUT variable
 if errorReport == None:
OUT = 0
else:
OUT = errorReport This text will be hidden

Hi @Scott_Bissett,

You didn’t reproduce the correct indentation of the python script.

# Copyright(c) 2016, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

# Import Element wrapper extension methods
import clr
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

import System
from System.Collections.Generic import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#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 )

def Unwrap(item):
	return UnwrapElement(item)

folderPath = IN[0]

if isinstance(IN[1], list):
    views = ProcessList(Unwrap, IN[1])
else:
    views = list(Unwrap(IN[1]))

if isinstance(IN[2], list):
	names = IN[2]
else:
	names = list(IN[2])

dwg_opt = IN[3]

RunIt = IN[5]

def ExportDwg(name, view, folder = folderPath):
	options = None
	settings = FilteredElementCollector(doc).WherePasses(ElementClassFilter(ExportDWGSettings))
	for element in settings:
		if element.Name == dwg_opt:
			options = element.GetDWGExportOptions()
			break 
		
	if options is None:
		options = DWGExportOptions()
	
	options.MergedViews = IN[4]
	views = List[ElementId]()
	views.Add(view.Id)
	result = doc.Export(folder, name, views, options)
	return result

if RunIt:
	try:
		errorReport = None
		# run export
		ProcessParallelLists(ExportDwg, names, views)
	
	except:
		# if error accurs anywhere in the process catch it
		import traceback
		errorReport = traceback.format_exc()
else:
	errorReport = "Please set the RunIt to True!"

#Assign your output to the OUT variable
if errorReport == None:
	OUT = 0
else:
	OUT = errorReport

Here’s the graph!

It works well for me so add your graph and your Revit file.

My apologies @Alban_de_Chasteigner, the indentation was correct in Dynamo, I just translated it poorly into the Forum post.

So the script will now run without errors, however when i open the exported DWG the line types/colours are still wrong so i believe the specified DWG Export Settings are not being applied.

Any further help is greatly appreciated.

@Alban_de_Chasteigner unfortunately as a new user i cannot upload Graphs.

You can use a dropbox, wetransfer or google drive link for the Revit file.

You can also use custom nodes of several packages.

export%20dwg

Link to the Graph and an almost empty revit file containing the Export settings:
https://drive.google.com/drive/folders/1DEKEQ00IsDi1ODTuYvEIdgnxeKgl0dLx?usp=sharing

Perhaps I am wrong but GeniusLoci_ExportDWG is the only node which allows user specified Export Setup?

This node is also the node which the python script I am using is based on however i have exactly the same Problem when trying to use the GeniusLoci node and it does not appear to use the DWG Export Settings specified

The problem comes from your export Setup.
It could be the modifiers in your “CADStudio_REVIT_zu_MEP” setup.

The graph works with any new random Export Setup in your Revit file.

So I’ve played around with the Export Settings and still no luck.

I have uploaded 4 screenshots to the Google drive of the Exports in AutoCAD:

https://drive.google.com/drive/folders/1DEKEQ00IsDi1ODTuYvEIdgnxeKgl0dLx?usp=sharing

There are two different Export Settings used in the screenshots, the REvit_zu_MEP Setup and a new Setup with no modifiers or anything like that. I then exported the sheet to DWG manually and using the Dynamo graph for each.

As you can see both work as expected when manually exporting and then the colours are incorrectly mapped when exported with Dynamo.

These tests would lead me to believe that something needs changed in the Dynamo script but I don’t know what else to try at the Moment.

It works well for me with my personal ExportDWGSetting (it replaces the colors and the names of layers).
The script in post 2 works also.
I’m running out of ideas :neutral_face:


@Alban_de_Chasteigner Ok so the Genius Loci_Export DWG in Document works for me.

I never checked it earlier, I thought seeing as the other Genius Loci node wasn’t exporting for me that this one wouldn’t either. Guess that’s my lesson learned.

Thanks again!