Find an objects class

Hi,

I want to be able to use Python to select all objects in the Revit document based on the what the user has selected in a ‘Select Model Element’ node.

So, the user would use the ‘Select Model Element’ node to select a wall and then when the Python code is run all walls would be selected in the UI.

The problem I have is how to construct a FilteredElementCollector based on the object selected.

Looking at the FilteredElementCollector class, there is a method called ‘OfClass’ which (I believe) selects all elements of a particular class.

I think this could work if I could work out the class of the element selected by the user in the ‘Select Model Element’ node.

I’ve used the dir() function to see what can be done with the selected element, and I can see that there is the ability to return the class with:

selectedobject.class

But this returns ‘IronPython.Runtime.Types.PythonType’ which is of no use to me.

Is there an easy way to determine an objects class to that I can use the FilteredElementCollector OfClass method to select objects.

Thanks

Hi @Kevin.Bell ,
you can do it like this :

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument



classname = UnwrapElement(IN[0]).__class__
OUT = FilteredElementCollector(doc).OfClass(classname).ToElements()
3 Likes

Great thanks!

I actually tried this but Dynamo reports that the classname variable is ‘IronPython.Runtime.Types.PythonType’ which up to now when I’ve come across has been an error in my coding…

Nonetheless, it works - thanks.

For the sake of others who may encounter this, UnwrapElement(IN[0]).__class__.__name__ is probably what you were looking for.