I’ve inherited some code from a previous developer, it looks like he used FamilyInstances.RetrieveNestedComponent as a starting point. I’m trying to dimension from a linked curtain wall. If the references are named it’s usually working out ok, but not all of them are. Even local things like the level should still have a reference and I’m having a real challenge understanding how to mix the two. I’d rather get back to just using standard nodes. There are things nested in the curtain wall without named references that have been hard to get, like in the corner post or a head jamb receptor.
https://forum.dynamobim.com/t/how-to-retrieve-nested-components-from-family-instance-in-link/84642
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
def parse_linked_reference(doc, linked_ref):
reps = linked_ref.ConvertToStableRepresentation(doc).split(":")
res = ""
first = True
for i, s in enumerate(reps):
t = s
if "RVTLINK" in s:
if i < len(reps) - 1:
if reps[i + 1] == "0":
t = "RVTLINK"
else:
t = "0:RVTLINK"
else:
t = "0:RVTLINK"
if not first:
res = res + ":" + t
else:
res = t
first = False
ref = Reference.ParseFromStableRepresentation(doc, res)
return ref
elements = UnwrapElement(IN[0]) if isinstance(IN[0], list) else [UnwrapElement(IN[0])]
additional_refs = IN[3]
link_refs = []
#reference_names = ["Top", "Bottom", "TOSlab", "BOIntMull"]
#reference_names = ["Top", "TOSlab", "BOIntMull"]
#reference_names = ["Top", "BOIntMull"]
reference_names = ["Top", "TOSlab"]
#reference_names = ["Top", "Bottom"]
#reference_names = ["Top"]
for x in elements:
for reference_name in reference_names:
reference = FamilyInstance.GetReferenceByName(x, reference_name)
if reference:
link_refs.append(reference)
# rf_1 = FamilyInstance.GetReferenceByName(x, "FabRightFrame")
# link_refs.append(rf_1)
# Keep only the first and last references
# link_refs = [link_refs[0], link_refs[-1]]
# Add the additional references to the list of references
link_refs.append(additional_refs)
line = IN[1].ToRevitType()
# Interval = IN[2] * 0.08333333333 # / 12
# Interval = IN[2]# / 12
linked_instance = IN[2].InternalElement
doc = DocumentManager.Instance.CurrentDBDocument
ref_array = ReferenceArray()
for ref_link in link_refs:
linked_reference = ref_link.CreateLinkReference(linked_instance)
ref = parse_linked_reference(doc, linked_reference)
ref_array.Append(ref)
# Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
dim = doc.Create.NewDimension(doc.ActiveView, line, ref_array)
OUT = dim
#TransactionManager.Instance.TransactionTaskDone()