Python Equivalent of Dynamo's Element.Geometry

I’m trying to get a number of processes converted from Dynamo to pyRevit so they can all be run from a single interface - almost there, but for one. With a fam that symbolizes drift loads, Dynamo’s Element.Geometry returns exactly what I need to work with to find the intersection between the two lines representing the range of the load and the curves of the members that intersect those lines.

image

image

I get that I probably need to extract curves rather dynamo lines for the two lines that matter, but can’t figure out how to extract them from the ‘GeometryElement’ that get_Geometry returns from the drift instance. I’ve messed around with bounding boxes, outlines, constructing edges out of coordinates, and it seems like there must be a more elegant solution (that actually works.) Any advice appreciated.

Figured out this piece of the puzzle - this drills down into the instance to return the 2 line objects:

def get_drift_lines(drift):

    options = Options()
    geom_elem = drift.get_Geometry(options)

    lines = []
    
    for geom_obj in geom_elem:

            # If this GeometryObject is an Instance, transform and get the line
            if isinstance(geom_obj, GeometryInstance):
                    transformed_geom_elem = geom_obj.GetInstanceGeometry(geom_obj.Transform)
                    for geo in transformed_geom_elem:
                            if isinstance(geo, Line):
                                    lines.append(geo)

    return lines

@Texmati ,

what are you collecting? lines ? can you show the whole code and what do you want in Revit?

KR

Andreas

trying to get the intersection points of the blue lines with the black lines in the snip above. I can retrieve a representation of the lines with the function shared above, and can get the curves of the structural members without issue, but can’t find an intersection - when I look at the end points pulled from the curves that I’m trying to associate, it looks like they aren’t in sync when it comes to the origin point of the coordinates that I’m getting. Here’s the code referencing the function above and what it’s spitting out.

def Drifter(drifts, joists):

    print("Calculating Drift Loads . . .")
    print(drifts)
    

    for d in drifts:

            startLine, endLine = get_drift_lines(d)

            print startLine,endLine
            print startLine.GetEndPoint(0), startLine.GetEndPoint(1)
            print endLine.GetEndPoint(0), endLine.GetEndPoint(1)

            for j in joists:
                  
                    jLoc = j.Location
                    jCurve = jLoc.Curve

                    print jCurve.GetEndPoint(0), jCurve.GetEndPoint(1)

It’s immediately clear that the Z axis difference would prevent an intersection. 20 would represent the elevation of the workplane. No idea where the 40 is coming from.

1 Like

For anyone this could help - I think I figured this out as well.

Needed to use GetSymbolGeometry instead of GetInstanceGeometry when determining the line locations.

This helped a lot:
https://thebuildingcoder.typepad.com/blog/2020/04/references-in-symbol-versus-instance-geometry.html

2 Likes

look up get_gridpoints function from query.py in pyrevitlib\pyrevit\revit\db for example of getting curve intersections. does this help?

@Texmati ,

whats you input?


def get_drift_lines(drift):
    options = Options()
    geom_elem = drift.get_Geometry(options)

    lines = []

    for geom_obj in geom_elem:

        # If this GeometryObject is an Instance, transform and get the line
        if isinstance(geom_obj, GeometryInstance):
            transformed_geom_elem = geom_obj.GetInstanceGeometry(geom_obj.Transform)
            for geo in transformed_geom_elem:
                if isinstance(geo, Line):
                    lines.append(geo)

    return lines

selection = uidoc.Selection #type: Selection

#🔷 Get Selected Elements
selected_elements = selection.GetElementIds()

intersect = get_drift_lines(selection)
print(selection)

Is this the right workflow?

KR

Andreas

interesting link, thanks