Revit 2026 Dynamo GeniusLoci

Hello. I want to use same Nodes in Revit 26-27. It works Revit 2025 but not Revit 2026 or 2027. Thanks.

Hi @yaseminV2XL5 for import dwg i think it need Autodesk.Revit.DB.Document as document not revit application document, does it work when leave empty ? and try set to pythonnet 3

You could add IronPython 2.7 (3.2.1) from the Package Mananger, however this is getting fairly old and no longer considered secure as it is not maintained and updated.

Use Get AllDocuments from Genius Loci, works with PythonNet 3


CAD Block also works with PythonNet 3

You are going to hit some fundamental issues between IronPython2 and PythonNet3 on the Import DWG node. You could update code below to work with PythonNet3. Changed lines have comments

# Create ElementId / .NET object
# linkedElem = clr.Reference[ElementId]()  # Not required for PythonNet 3

TransactionManager.Instance.ForceCloseTransaction()
TransactionManager.Instance.EnsureInTransaction(doc)
for view in range(len(views)):
    _, linkedElem = doc.Import(filePaths[view], options, views[view], None)  # Method `out` as handled by PythonNet 3
    viewsplaced.append(views[view])
    importinst = doc.GetElement(linkedElem)  # linkeElem is now a ElementId by default
    importinstance.append(importinst)
    CADLink = doc.GetElement(importinst.GetTypeId())
    CADlinktype.append(CADLink)
    outName.append(CADLink.Category.Name)  # Direct access to the name of the category of the CADLinkType
    if not allView :
        importinst.get_Parameter(BuiltInParameter.IMPORT_BACKGROUND).Set(order)
TransactionManager.Instance.TransactionTaskDone()

Hi @sovitek und @Mike.Buttery . Thanks @Mike.Buttery. Get AllDocuments und CAD Block works with PythonNet 3. But Import DWG does not work with changed lines. I try it with another python code.

Hey @yaseminV2XL5 you can try as here as see if it better…should work for pythonnet 3…works here for 26, not tested 27, basic the same as Mike show :wink:

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

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import System
import System.Reflection

raw_doc     = IN[0]
filePaths   = IN[1] if isinstance(IN[1], list) else [IN[1]]
raw_views   = IN[2]
customscale = IN[3]
colormode   = IN[4]
placement   = IN[5]
unit        = IN[6]
allView     = IN[7]
order       = IN[8]

inputdoc = [UnwrapElement(x) for x in raw_doc] if isinstance(raw_doc, list) else [UnwrapElement(raw_doc)]
views    = [UnwrapElement(x) for x in raw_views] if isinstance(raw_views, list) else [UnwrapElement(raw_views)]

doc = DocumentManager.Instance.CurrentDBDocument if inputdoc[0] is None else inputdoc[0]

options = DWGImportOptions()
options.AutoCorrectAlmostVHLines = True
options.OrientToView = True
options.ThisViewOnly = not allView
options.VisibleLayersOnly = True
options.CustomScale = customscale

if colormode is not None:
    options.ColorMode = colormode
if placement is not None:
    options.Placement = placement
if unit is not None:
    options.Unit = unit

bf = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public
importMethod = None
for m in doc.GetType().GetMethods(bf):
    if m.Name == "Import":
        params = m.GetParameters()
        if (len(params) == 4
                and params[1].ParameterType.FullName == "Autodesk.Revit.DB.DWGImportOptions"
                and params[3].ParameterType.FullName == "Autodesk.Revit.DB.ElementId&"):
            importMethod = m
            break

viewsplaced    = []
outName        = []
CADlinktype    = []
importinstance = []

TransactionManager.Instance.ForceCloseTransaction()
TransactionManager.Instance.EnsureInTransaction(doc)

for i in range(len(views)):
    args = System.Array[System.Object]([
        System.String(filePaths[i]),
        options,
        views[i],
        ElementId.InvalidElementId
    ])
    importMethod.Invoke(doc, args)
    linkedId = ElementId(int(str(args[3])))

    viewsplaced.append(views[i])
    importinst = doc.GetElement(linkedId)
    importinstance.append(importinst)

    CADLink = doc.GetElement(importinst.GetTypeId())
    CADlinktype.append(CADLink)
    outName.append(CADLink.Name)

    if not allView:
        importinst.get_Parameter(BuiltInParameter.IMPORT_BACKGROUND).Set(order)

TransactionManager.Instance.TransactionTaskDone()

if isinstance(IN[0], list):
    OUT = viewsplaced, outName, CADlinktype, importinstance
else:
    OUT = viewsplaced[0], outName[0], CADlinktype[0], importinstance[0]

Thanks @sovitek .It works now. :slightly_smiling_face: :clap: