Export DWG From Template File (Post 3)

I’m trying to export DWG’s with options provided from a template file and unfortunately the python script that I am using (originally @Konrad_K_Sobon’s) is throwing a:
AttributeError: ‘UnkownElement’ object has no attribute ‘GetDWGExportOptions’ error message.

I know it isn’t a problem with the Method, because it is defined in the API.

Therefore, I’m assuming that I’m missing something when I try to get the ExportDWGSettings element into the python script.

Anyway here’s my very lightly modified Python Script, with the line in question being
options = IN[5][0].GetDWGExportOptions()
following “def ExportDWG” near the bottom (I wish there were code line numbers :slightly_smiling_face: #site-feedback )

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

RunIt = IN[4]

def ExportDwg(name, view, folder = folderPath):
	#options = DWGExportOptions()
	options = IN[5][0].GetDWGExportOptions()
	options.MergedViews = IN[3]
	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

-Thanks

Have you tried unwrapping the ExportDWGSettings object?

1 Like

I swear I had tried that before, but that did the trick, Thanks.

EDIT: This graph relies on Clockwork and Rythm nodes :wink:

Here’s the graph for future reference:
DWGExporter.dyn (29.8 KB)


And the slightly modified 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])

RunIt = IN[4]

#Gets the first ExportSettings item from the template
expElement = UnwrapElement(IN[5][0])

def ExportDwg(name, view, folder = folderPath):
	options = expElement.GetDWGExportOptions()
	options.MergedViews = IN[3]
	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
1 Like