I have a generic family and I have a line inside it. I load this family inside my project and I need to catch this line which belong to a subcategory I know it’s name to get it’s length or coordinates of start or end points for examples.
The Python script below will look through the family geometry and return the geometry that belongs to a specific subcategory. It is written for a single family instance but can be turned into one that handles a list of elements and/or subcategory names.
# Enable Python support and load DesignScript library and Revit nodes and services
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
# Document
doc = DocumentManager.Instance.CurrentDBDocument
# IN
elem = UnwrapElement(IN[0]) # Unwrap family instances
subcat = IN[1] # names of subcategory
# Lists
geometries = []
# Options
geomOptions = Options()
for geom in elem.get_Geometry(geomOptions):
for g in geom.GetInstanceGeometry():
graphics = doc.GetElement(g.GraphicsStyleId)
if graphics != None:
if subcat == doc.GetElement(g.GraphicsStyleId).GraphicsStyleCategory.Name:
geometries.append(g.Convert())
OUT = geometries
Hope this helps,
Thomas
You may also want to check out this on The Building Coder:
it works smoothly, so nice I like it but if I have many lines and each line belong to different subcategories … might you if you don’t mind update this code … unfortunately, I don’t know python
This revised version takes a list of elements and a list of subcategory names and returns a list of geometries and a corresponding list of subcategory names that the geometry belongs to enable further filtering / sorting.
# Enable Python support and load DesignScript library and Revit nodes and services
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
# Document
doc = DocumentManager.Instance.CurrentDBDocument
# IN
elems = UnwrapElement(IN[0]) # Unwrap family instances
subcats = IN[1] # names of subcategories
# Lists
geometries = []
subcatsOut = []
# Options
geomOptions = Options()
for elem in elems:
geometries.append([])
subcatsOut.append([])
for geom in elem.get_Geometry(geomOptions):
for g in geom.GetInstanceGeometry():
graphics = doc.GetElement(g.GraphicsStyleId)
if graphics != None:
for subcat in subcats:
if subcat == doc.GetElement(g.GraphicsStyleId).GraphicsStyleCategory.Name:
geometries[-1].append(g.Convert())
subcatsOut[-1].append(subcat)
OUT = geometries, subcatsOut
Hi everyone, i was trying to use this node, but it gives me the error in the image. I copy/pasted the Python script. I’m also using Revit 2020. What could it be?