Export View Set To DWG

archi-lab
revit

#1

2d coordination sections are required by one of our sub-contractors. I have created a graph that creates the sections at the agreed locations, names the sections according to the naming convention, creates a view set of the section views exports them as DWF files & PDF files, but they also require them as DWG files. I cannot find a way of exporting them through dynamo so I have to go back to Revit and export the manually. I would appreciate it if anyone has any ideas.

Regards

Darren


Export all Revit views to Single DWG File
Export to DWF - To use in Navis and DesingReview
#2

want to post what you have so far so that we all have a starting point? Remember that sample files, images and code goes a long way in getting everyone up to speed.

Thanks!

Ps: Have a look at this: http://thebuildingcoder.typepad.com/blog/2010/09/autocad-2010-dwg-export.html


#3

The graph is quite big for an image so I have attached the DYN file. At the moment it is working on all gridlines but once we get the agreed list on an excel spreadsheet it will use that to determine the sections to be created.

As to the Building coder link I don’t realy have any experience with python or coding so it is a little beyond my skills at the moment

Thanks

Darren

Section By Gridline.dyn (168.3 KB)


#4

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 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[3]

def ExportDwg(name, view, folder = folderPath):
	options = DWGExportOptions()
	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

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.

Good luck!

Ps. Get All Views node comes from Archi-lab_Grimshaw package.


ReWrite Export Options DWG
Export revit views to cad
Create Error log for debugging python script?
Revit Family to CAD
Dividing parts with dynamo
#5

Thanks Konrad

It is very much appreciated.

Regards

Darren


#6

Thank you for the information of this discussion. We are looking for exporting dwg with “export options” we have set up in our models.

We used the following script but something doesn’t work:

options = None
settings = FilteredElementCollector(doc).WherePasses(ElementClassFilter(type(ExportDWGSettings)))
for element in settings:
	if element.Name == dwg_opt:
		options = element.GetDWGExportOptions()
		break
if options is None:
	options = DWGExportOptions()

The error is showing a problem in the command (type(ExportDWGSettings)

It is for sure a problem regarding the translation of a C# code I found on the net in python.
Could you help me please with this issue?

Thank you in advance.


#7

try getting rid of “type” in that filter so:

settings = FilteredElementCollector(doc).WherePasses(ElementClassFilter(ExportDWGSettings))


#8

Hi @Konrad_K_Sobon

Can i use the same script for exporting sheets?

# 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[3]

def ExportDwg(name, view, folder = folderPath):
	options = DWGExportOptions()
	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

Export View Set To DWG issue
#9

Hi @Konrad_K_Sobon,

I am getting error when i feed sheets to export.


#10

If you use the “Drawing Sheets” in the Get All Views node there is no need to have a separate node to gather the sheet category.

I did have one other question that I am hoping will be an easy enough addition to the Python code? Is there any way when you are exporting the sheet to get the “Export views on sheets and links as external references” to be unticked by default?

It is an awesome workflow, very useful thanks Konrad


#11

your names have forward slashes in them. It’s an illegal character in windows environment. Please replace those with underscores or remove all together.


#12

Look at the export settings dialog. that option is there and you can save that to a template to use with the workflow.


#13

Cheers, I was trying to create a difficult solution from a simple problem.


#14

@Konrad_K_Sobon Thanks for the info. I am still unable to export sheets. It gives me only views.


Export Geometry created by Mesh.Toolkit for laser cutter
#15

What is “e.dwg”? Have you opened that file to see what’s in it? It seems to me that your export works just fine, but you get all the views in as links hence it also generates DWGs for all the views. Just look at the conversation I had with @Scott_Crichton in this thread and make sure that you don’t ask Revit to generate these.


#16

@Konrad_K_Sobon i have total 6 sheets in my graph and i named those sheets by a,b,c,d,e,f. When open e.dwg it shows only view which was inserted in sheet. It doesn’t export sheet.


#17

The sheet will show up in a layout tab in Autocad. In case you didn’t check that.


#18

@Einar_Raknes Thanks for the reply. I checked in layout nothing is there. I think above python scripts works only for views but not sheets.


#19

@Konrad_K_Sobon My bad i just noticed it is exporting but with “Views on sheets and links as external references”. I changed settings dialog but it didn’t helped :confused:

@Scott_Crichton did you had success in doing that?


#20

When I try it I get the same results - it exports all the views as separate sheets along with the sheets. Not totally ideal. Has to be something really simple we are missing.