import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import RevitAPI
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
import System
from System import Array
from System.Collections.Generic import *
cat = [BuiltInCategory.OST_ReferenceLines]
bic = List[BuiltInCategory](cat)
filter = ElementMulticategoryFilter(bic)
fec = FilteredElementCollector(doc).WherePasses(filter).ToElements()
OUT = fec
in this topic.
It works fine when you work inside a family document. But i would like it to work from the project environment on a list of Family Instances. So i tried to edit the Python code, this what i have so far.
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
elements = UnwrapElement(IN[0]) if isinstance(IN[0],list) else [UnwrapElement(IN[0])]
#Get ReferenceLines from Families
for element in elements:
referencelines = []
cat = [BuiltInCategory.OST_ReferenceLines]
bic = List[BuiltInCategory](cat)
filter = ElementMulticategoryFilter(bic)
fec = FilteredElementCollector(doc).WherePasses(filter).ToElements()
referencelines.append(fec)
OUT = referencelines
I use nodes from the āGenius Lociā package to select the āAutodesk.Revit.DB.Referenceā elements inside the families.
Only I canāt read any information from the mentioned DB elements (e.g. subcategory). So then I have a list of References but no information to sort them.
It is therefore not my intention to draw reference lines in the project environment. I would just like to consult the (unwrapped) reference lines within the families to read out the parameter values. I could then use these parameter values to sort the DB elements, otherwise I donāt know if Iām selecting the correct reference as the basis for dimensioning.
Thatās the correct approach. But you canāt use a FilteredElementCollector at that level. It is going to be family instance by family instance.
Youāll need to make a list of tuples to track what element has what reference list.
[[Family instance, Reference Line]
[Family instance, Reference Line]
etc]
Select References Inside the unwrapped FamilyInstances.
Use the method above to get the geometry objects from the References (ModelLines/Planes).
Get the subcategory parameter from the geometry objects.
Write the references and corresponding subcategory parameters to the output.
But Iām confused about the depth of the nested for loops and the intermediate writing of the data to Tuples.
Any advice to point me in the right direction (for the next step) is appreciated.
I have some bad experiences asking ChatGPT to create Python code, its not ready to do that. But it helps me a lot to get a better understanding if i ask ChatGPT advise for little steps. The steps above would result in the next āBETAā code.
# inputs
inFamilies = IN[0]
# outputs
outReferences = []
outCategories = []
# iterate over the input FamilyInstances
for family in inFamilies:
# unwrap the FamilyInstance
element = UnwrapElement(family)
# get the references from the element
references = element.GetReferences(FamilyItemReferenceType.Both)
# iterate over the references
for reference in references:
# get the geometry object from the reference
geoObject = element.GetGeometryObjectFromReference(reference)
# get the subcategory parameter from the geometry object
subcategory = geoObject.GraphicsStyle.GraphicsStyleCategory.Subcategory
# store the subcategory parameter in a list
outCategories.append(subcategory.Name)
# create a tuple of the reference and subcategory parameter
outTuple = (reference, subcategory.Name)
# append the tuple to the output list
outReferences.append(outTuple)
# return the output lists
OUT = (outReferences, outCategories)
As i said there might be a lot wrong with this code, but for now i would like to know if this is the right structure to achieve what i have in mind.