findBRepUsingRay, multiple entity types

findBRepUsingRay, multiple entity types

ebunn3
Advocate Advocate
496 Views
4 Replies
Message 1 of 5

findBRepUsingRay, multiple entity types

ebunn3
Advocate
Advocate

Is it possible to use the findBRepUsingRay with multiple entity types (face, edge, vertex).  I want to return information on all three but don't want to run the function 3 different times if I don't have to.

 

Thanks,

 

Eric

0 Likes
Accepted solutions (1)
497 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor

Hi @ebunn3 .

 

I'm not sure I understand your purpose. Why don't you create your own function to handle this?

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui: adsk.core.UserInterface = None
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        hits = findBReps_UsingRay(
            root,
            adsk.core.Point3D.create(0,0,0),
            adsk.core.Vector3D.create(0,0,1),
        )

        for idx, ent in enumerate(hits):
            print(f'{idx} - {ent.objectType}')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def findBReps_UsingRay(
        comp: adsk.fusion.Component,
        originPoint: adsk.core.Point3D,
        rayDirection: adsk.core.Vector3D,
        proximityTolerance: float = -1.0,
        visibleEntitiesOnly: bool = True,
        hitPoints: adsk.core.ObjectCollection = None
    ) -> adsk.core.ObjectCollection:

    brepEntTypes = [
        adsk.fusion.BRepEntityTypes.BRepFaceEntityType,
        adsk.fusion.BRepEntityTypes.BRepEdgeEntityType,
        adsk.fusion.BRepEntityTypes.BRepVertexEntityType,
    ]

    ents: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
    pnts: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
    hits: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()

    for entType in brepEntTypes:
        objs = comp.findBRepUsingRay(
            originPoint,
            rayDirection,
            entType,
            proximityTolerance,
            visibleEntitiesOnly,
            hits
        )

        if objs.count < 1:
            continue

        for o, h in zip(objs, hits):
            ents.add(o)
            pnts.add(h)

    hitPoints = hits

    return ents
0 Likes
Message 3 of 5

ebunn3
Advocate
Advocate
Accepted solution

Thank you.  Let me take a look at your example and see if I can make that work.  I'm used to a similar function in Solidworks that will take an array of points, and return back the hit points and entities on anything it hits. Makes sense what you provided but I have to look at it a little harder.  Thanks.

 

Eric

0 Likes
Message 4 of 5

BrianEkins
Mentor
Mentor

One thing to consider, that's also mentioned in the documentation for findBRepUsingRay, is that if you hit a vertex you've also hit the edges that are connected by that vertex. It also means you've hit the faces that are connected by those edges.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 5

ebunn3
Advocate
Advocate
Thanks Brian.
0 Likes