Batch link DWGs in Drafting Views

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;
7 Likes

Great work @mmoscatelli :ok_hand:.

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

1 Like

Thanks Martin,

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

Hi mmoscatelli :wink:
Thanks for providing this script :slight_smile: It works for one view, but what do I have to change to get it to work with multiple views?

It is my goal to link it f. ex. 5 DWG Files to 10 Views. When I generate an input list with 10 dwgs links (some of them doubled, because they are supposed to be linked on two views) and 10 views it does not work.

I get the following error:
image
Is the “LinkedElem = clr.ReferenceElementId” the problem? I never saw this one before…

Thanks and kind regards,
Jannis