Export dwg saved set and then reload imported cad files

I am looking for some insight on whether something is possible.

A workflow we have in the office is as follows for different apartment layouts:

-We create the wall/door/window layout in revit
-We put each of these layouts in it’s own view
-We save these views when doing an export to dwg
-We import the dwgs and use these in our drawings

I am wondering if it would be possible to create a script that would:

  1. Export the saved dwg list of views which would overwrite the existing dwgs
  2. Then reload the overwritten dwg files.

Thanks,

-Ian

@kslifter a bit late, but worth checking, hope it helps:

import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
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)
doc = DocumentManager.Instance.CurrentDBDocument
folderPath = IN[0]
if isinstance(IN[1], list) : fileNames = IN[1]
else : fileNames = [IN[1]]
allViews = FilteredElementCollector(doc).OfClass(View)
viewsD = {}
views = []
for view in allViews:
	if not view.IsTemplate:
		viewsD[view.Name] = view
for name in fileNames:
	for key in viewsD.keys():
		if key == name:
			views.append(viewsD[key])
			break
refresh = IN[2]
cadLinks = []
dwgOptions = DWGExportOptions()
for view, f in zip(views, fileNames):
	viewsE = List[ElementId]()
	viewsE.Add(view.Id)
	doc.Export(folderPath, f, viewsE, dwgOptions)	
TransactionManager.Instance.EnsureInTransaction(doc)
cads = FilteredElementCollector(doc).OfClass(ImportInstance)
if refresh == True or refresh == False:
	for cad in cads:
		if cad.Category.Name.EndsWith(".dwg"):
			typeId = cad.GetTypeId()
			cadLink = doc.GetElement(typeId)
			cadLink.Reload()
			cadLinks.append(cad.Category.Name)			
TransactionManager.Instance.TransactionTaskDone()
OUT = cadLinks
1 Like

Wow, thanks! I’ll try it out!

I am not necessarily new to Dynamo, but still not very proficient in it. I haven’t really dived into Python Scripts at all. How do I go about inputting the script into the node?

@kslifter just copy/ paste the script content onto a Python Script node

1 Like

I got this error code. What is the workflow when using this script?

@kslifter you need to have the dwg files already linked in the Revit file, and you have to Browse to the folder the dwg files are found at using the Directory Path node.
when you want to mention someone please use the “@” character.