Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

findBRepUsingRay, multiple entity types

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
ebunn3
193 Views, 4 Replies

findBRepUsingRay, multiple entity types

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

4 REPLIES 4
Message 2 of 5
kandennti
in reply to: ebunn3

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
Message 3 of 5
ebunn3
in reply to: kandennti

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

Message 4 of 5
BrianEkins
in reply to: ebunn3

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
in reply to: BrianEkins

Thanks Brian.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report