Dynamo 3.3.xx and LinkDWG custom node

Hello everyone,

While working with IronPython, I’ve used several times an script I made using GeniusLoci custom node “Link DWG”. Now I need to use it on Revit2025, so CPython3 is in the way, and making this node not to work properly. Even after setting it to CPython3 version, it won’t work. I’ve been looking for a solution for hours now and I even can’t find the problem on the Python code to solve it by myself, since I didn’t find anything on forum or the internet.

Could I get any help understanding what part of the coding/API changed after IronPython?

Custom node Python code just in case it helps:

#Based on a script by Konrad Sobon
#Additions by Alban de Chasteigner 2018

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

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

filePaths = IN[0] if isinstance(IN[0],list) else [IN[0]]
views = UnwrapElement(IN[1]) if isinstance(IN[1],list) else [UnwrapElement(IN[1])]
customscale = IN[2]
colormode = IN[3]
placement = IN[4]
unit = IN[5]
allView = IN[6]
viewsplaced,outName,CADlinktype,importinstance = [],[],[],[]

options = DWGImportOptions()
options.AutoCorrectAlmostVHLines = True
options.OrientToView = True
if allView :options.ThisViewOnly = False
else: options.ThisViewOnly = True
options.VisibleLayersOnly = True
options.CustomScale = customscale
if colormode == None: ImportColorMode.Preserved
else: options.ColorMode = colormode
if placement == None: ImportPlacement.Shared
else :options.Placement= placement
if unit == None : ImportUnit.Default
else : options.Unit = unit

# Create ElementId / .NET object
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])
        importinst = doc.GetElement(linkedElem.Value)
        importinstance.append(importinst)
        CADLink = doc.GetElement(importinst.GetTypeId())
        CADlinktype.append(CADLink)
        outName.append(Element.Name.GetValue(CADLink))
        
if isinstance(IN[0], list): OUT = viewsplaced,outName,CADlinktype,importinstance
else: OUT = viewsplaced[0],outName[0],CADlinktype[0],importinstance[0]

Thank you in advance

Hi,

ref and out parameters have specific syntax in PythonNet

Try updating it with the PythonNet documentation.

For more information, there is a new Python engine (“PythonNet3”) available in the Package Manager.

Hi,
Thank you for the link. It took me a long time to understand, since my Python knowledge is very limited by now, but thanks to those clarifications and a little boost from chatgpt I came to the solution and iit’s working now.

Thank you, and have a great day!

1 Like