Hard Coding Element Types

Hello I’m trying to hard code this element type - reference plane with code block
image

something similar to what I did for Categories node below
image

However, it seems like its not working so I tried python code

import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
clr.AddReference(‘RevitServices’)

import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

reference_plane = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ReferencePlane).WhereElementIsNotElementType().ToElements()

OUT = project_info[0]

which is throwing an error.
Not sure where to fix

Any suggestion would be greatly appreciated. Thank you very much!

Hi @mixology,

Write in a code block instead :
DSCore.Types.FindTypeByNameInAssembly("ReferencePlane", "RevitAPI");

For the python script, change the OUT =

reference_plane = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ReferencePlane).WhereElementIsNotElementType().ToElements()

OUT = reference_plane
4 Likes

Here in designscript

7 Likes

This isn’t the most efficient Python based method, but this is how I do it in Crumple. You could probably build in the entire process to one Python node, but I just use a node in the package twice to avoid writing the code twice also.

It is probably most effective when calling on one element type or a list of them, but once you go to multiple sublists it can get a bit inefficient as it generates the type list each time.

It’s probably one of my most used nodes personally.

Outside

The Python in the element types node is large in part lifted from Clockwork.

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
import System.Reflection
import System.AppDomain

rAssembly = [x for x in System.AppDomain.CurrentDomain.GetAssemblies() if x.GetName().Name == 'RevitAPI'][0]
rElement = [x for x in rAssembly.GetTypes() if x.Name == 'Element' and x.Namespace == 'Autodesk.Revit.DB'][0]

etypes = [x for x in rAssembly.GetTypes() if x.IsClass and x.IsSubclassOf(rElement)]
enames = [t.Name for t in etypes]

OUT = [etypes, enames]
3 Likes