Batch link DWGs in Drafting Views

#1

I have corrected Python script to link two o more DWG.
Enjoy

############################################
#Copyright 2019							 ###
#by Marco Moscatelli 		feat Konrad	 ###
#Email: flytelli@gmail.com				 ###
############################################

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

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

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

filePaths = IN[0]
views = UnwrapElement(IN[1])

viewsplaced=list()

options = DWGImportOptions()
options.AutoCorrectAlmostVHLines = True
options.ColorMode = ImportColorMode.BlackAndWhite
options.OrientToView = True
options.ThisViewOnly = True
options.VisibleLayersOnly = True
options.CustomScale = 100
#options.Placement = Origin

LinkedElem = clr.Reference[ElementId]()

for view in range(len(views)):
	TransactionManager.Instance.EnsureInTransaction(doc)
	
	doc.Link(filePaths[view], options, views[view], LinkedElem)
	
	TransactionManager.Instance.TransactionTaskDone()
	viewsplaced.append(views[view])


#Assign your output to the OUT variable.
OUT = viewsplaced;
5 Likes

#2

Great work @mmoscatelli :ok_hand:.

I’ve changed the category to Share, since you provided a working solution.

1 Like

#3

Thanks Martin,

I’m newbie. It’s my first post :grin:

0 Likes