python: create start point/end point for each model line inside mass family

python: create start point/end point for each model line inside mass family

ellliaz
Participant Participant
918 Views
3 Replies
Message 1 of 4

python: create start point/end point for each model line inside mass family

ellliaz
Participant
Participant

Hi, i created a family mass composed by model lines, i want to place a structural framing beam for each line i've in the family. i wrote a code to place a point at the beginning and end of each line, but i get an empty list as result. Do you have some suggestion? 

 

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

points = []

mass_instances_collector = FilteredElementCollector(doc).OfClass(FamilyInstance).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Mass)

for mass_instance in mass_instances_collector:
    family = mass_instance.Symbol.Family
    if family.FamilyCategory.Id == BuiltInCategory.OST_Mass:
        mass_geometry = mass_instance.Symbol.get_Geometry(Options())
        for geo_obj in mass_geometry:
            if isinstance(geo_obj, GeometryInstance):
                geometry = geo_obj.GetInstanceGeometry()
                for g in geometry:
                    if isinstance(g, Line):
                        line = g
                        start_point = line.GetEndPoint(0)
                        end_point = line.GetEndPoint(1)
                        points.append((start_point.X, start_point.Y, start_point.Z))
                        points.append((end_point.X, end_point.Y, end_point.Z))

OUT = points

 

0 Likes
Accepted solutions (1)
919 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni

The call to append a point to the list is wrapped in several if clauses. I would assume that one or more of those is failing, and therefore no points are added. Run your code in a debugger, step through it line by line, and you will see which assumptions are failing.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 4

architect.bim
Collaborator
Collaborator
Accepted solution

Hi!

In your case there is no need to get the Family and the Symbol Geometry for the mass element. Just extract the geometry directly from the instance and everything will work fine and you will get the desired points in the output.

for mass_instance in mass_instances_collector:
    for g_element in mass_instance.Geometry[Options()]:
        if isinstance(g_element, GeometryInstance):
            for item in g_element.GetInstanceGeometry():
                if isinstance(item, Line):
                    start_point = item.GetEndPoint(0)
                    end_point = item.GetEndPoint(1)
                    points.append((start_point.X, start_point.Y, start_point.Z))
                    points.append((end_point.X, end_point.Y, end_point.Z))

 


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 4 of 4

ellliaz
Participant
Participant

Thanks it solved the issue 😊 even though i changed the code a little 

for mass_instance in mass_instances_collector:
    mass_geometry = mass_instance.get_Geometry(Options())
    for geo_obj in mass_geometry:
        if isinstance(geo_obj, GeometryInstance):
            geometry = geo_obj.GetInstanceGeometry()
            for g in geometry:
                if isinstance(g, Line):
                    line = g
                    start_point = line.GetEndPoint(0)
                    end_point = line.GetEndPoint(1)
                    start_points.append(start_point)
                    end_points.append(end_point)