How to acces an CurveArrays?

Hello,

for any reason, my roof worklines apear as modelines how can i access them correctly
here just array only:

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#functions
def tolist(x):
    if hasattr(x,'__iter__'): return x
    else: return [x]

#collector
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs)
all_Roofs = tolist(collector.WhereElementIsNotElementType().ToElements())

profiles = [i.GetProfiles() for i in all_Roofs]

curves = [c.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble() for c in profiles]

OUT = all_Roofs, profiles, curves

KR

Andreas
2023-11-14_10h34_24

The GetProfiles() method returns a ModelCurveArrArray which you will have to iterate through

Try this line
curves = [c.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble() for arr in profiles for c in arr]

3 Likes

grafik

def tolist(x):
    if hasattr(x,'__iter__'): return x
    else: return [x]

#collector
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs)
all_Roofs = tolist(collector.WhereElementIsNotElementType().ToElements())

profiles = [i.GetProfiles() for i in all_Roofs]

curves = [c.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble() for arr in profiles for c in arr]

#curves = [c.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble() for c in profiles]

OUT = all_Roofs, profiles, curves

This is like Inception or perhaps ModelCurveArrays all the way down. I think the better way to try this is to use other methods to get to the geometry.
Add a function. This is not the way I would do it with pure python, however this handles the .NET objects better

def flatten(x):
    try:
        return [a for i in x for a in flatten(i)]
    except:
        return [x]

Your collector is assuming FootPrintRoof types - perhaps make it explicit

roofs = (
    FilteredElementCollector(doc)
    .OfClass(FootPrintRoof)
    .WhereElementIsNotElementType()
    .ToElements()
)

And finally use the GeometryCurve.Length attribute of the ModelCurve to get your elements’ length

OUT = [mc.GeometryCurve.Length for mc in flatten([r.GetProfiles() for r in roofs])]
1 Like

To keep nesting of multiple roofs use this

modelcurves = [flatten(r.GetProfiles()) for r in roofs]

OUT = [[c.GeometryCurve.Length for c in mc] for mc in modelcurves]
2 Likes