Issues with Wrapping and Unwrapping Objects in Dynamo with Python

Hello everyone, I am currently and will be using Revit API for both Dynamo and Pyrevit. I have only just started studying for a few months, and I am facing issues when using Python script in Dynamo. Sometimes objects need to be wrapped and unwrapped between Dynamo and Revit. Basic objects seem to be unwrapped easily, but for some other objects, I have to use Conversion Methods like ToProtoType(), ToPoint(), and some others I am not familiar with, such as OverrideGraphicSettings… Is there any resource that comprehensively covers all these aspects so I can work more easily?

Although I found a workaround, here is an example. My Python code uses the same code and both inputs are OverrideGraphicSettings , but one is Autodesk.Revit.DB.OverrideGraphicSettings , and the other is Revit.Filter.OverrideGraphicSettings , one’s work and one’s not work. I am afraid that in the future, if I don’t fully understand it, I will encounter similar issues without a solution.



When your elements are come “in” (IN[0]) to access all proberties you have to unwrap Elements.

you can skip unwrapping when you collect in the code f.e.

# 🛒 collector
elements = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()


PyRevit for now is poor in geometry representation. But that can change, because it is a OpenSourceTool (There is no Asset Manager who freezes inovation). So for now you can only use Revit Geometry. You have to know well the geometry hierachy…

Your code will run faster and more stable in clean python.

In poth applications you have a different framing regarding transactions moduls and outputs. But it is easy to understand.


Start here Take Dynamo Further 🚀 | Dynamo Python Primer



you can find some other information here

But in this case Revit.Filter.OverrideGraphicSettings is not an Element (UnwrapElement do not work), so it will be necessary to use reflection because the accessibility of the property ‘InternalOverrideGraphicSettings’ is restricted

here a workaround

import clr
import sys
import System
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

#import net library
from System.Collections.Generic import List

import Revit

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

from System.Reflection import BindingFlags

def toList(x):
	if isinstance(x, (list, dict)) or \
			(hasattr(x, "GetType") and x.GetType().GetInterface("ICollection") is not None):
		return x
	else : return [x]

lst_dyn_ovg = toList(IN[0])

lst_rvt_ovg = []

for dyn_ovg in lst_dyn_ovg:
	invokeObj = clr.GetClrType(dyn_ovg.GetType()).InvokeMember('InternalOverrideGraphicSettings', 
												BindingFlags.InvokeMethod | BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, 

OUT = lst_rvt_ovg

1 Like

hi @c.poupin
Thank you a lot, but could u tell me how you know from System.Reflection import BindingFlags
is the method for it , and where to learn all of these advanced thing, OMG so much thing need to know… i look at all your code in forum, so much thing really new for me

this one gonna help me alot but most of them i already know

1 Like

thank you @Draxl_Andreas and @Mike.Buttery , it’s gonna help me a lot

1 Like