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: 

General Project Questions

12 REPLIES 12
Reply
Message 1 of 13
casey.rogers
549 Views, 12 Replies

General Project Questions

I am working on a lengthy project that involves iterating through a brep body. I expect to have a lot of small questions, so I figured I'd lump them all into one thread that I'll update as I go along so I don't clutter the forum. I appreciate any help I can get! Here is the first question so far:


1) When I have a brep face and I call its edges property, are the edges returned to me in any particular order? I would like to, given a brep face, iterate through its edges in clockwise order (as seen from the outside of the Brep body). CCW would also work, I primarily just need it to be a consistent order.

12 REPLIES 12
Message 2 of 13
casey.rogers
in reply to: casey.rogers

For some reason the forum doesn't seem to want to let me edit my original post, so I'll start the rest of my questions here:

2) I can't seem to find the combine tool through the API, is it not available via the API yet?

Message 3 of 13
casey.rogers
in reply to: casey.rogers

Ugh it seems I have a small timelimit to edit my posts, I guess I'll have to triple post:

3) Is there an easy way to find the length of a Brep edge? I'm about to write my own function to do the math, but it seems like a pretty basic task so I'd imagine it'd already be in the API but it doesn't seem obviously available via the Brep edge object's properties.

 

EDIT: answered this one myself, will use the geometry.distanceTo method for the start and end vertices.

Message 4 of 13
ekinsb
in reply to: casey.rogers

Answer to Question 1: You should not depend on the order that edges are returned from a face.  In fact for many faces an edge order doesn't make sense because there can be multiple unconnected edges as shown in the figure below.  The highlighted face has 20 edges with just some of them connecting.  What you want is that from a BRepFace you can use the loops property to get a BRepLoops object.  A BRepLoop is a set of connected edges within a loop.  In picture below there are 5 BRepLoops.  Every face has one loop that defines it's outer shape and it can have zero to any number of internal loops.  The isOuter property of the BRepLoop object indicates if it's an inner or outer loop.  The edges of an outer loop are returned in a CCW direction and the inner are returned in a CW direction.

 

Loops.png


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 13
ekinsb
in reply to: casey.rogers

Answer to question 2: The combine feature is not supported by the API in the current release of Fusion but is supported in the upcoming release.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 13
ekinsb
in reply to: casey.rogers

Answer to question 3: Getting the distance between the start and end point will only work for linear edges.  We should probably make it easier than this, but the function below will return the length of an input edge.

 

def edgeLength(edge):
    geometry = edge.geometry
    curveEval = geometry.evaluator
    
    # Get the parameter extents of the curve.
    results = curveEval.getParameterExtents()

    # Get the length of the curve between the start and end parameters.
    results = curveEval.getLengthAtParameter(results[1], results[2])
    
    length = results[1]
    
    return length

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 13
casey.rogers
in reply to: ekinsb

Thanks for all the replies! I should clarify, my add-in is iterating through meshes that are imported stls converted to BRep surface or solid bodies so all edges are linear and all loops are outer loops.
1) I unfortunately can't use the BRepLoops object as my add-in is leveraging the fact that any given edge is shared between two faces. In practice, I'm pretty sure my add-in is iterating through the edges in CCW order which is consistent with the BRepLoops outer loop behavior.
2) When will that be released? My add-in is pretty dependent on the combine tool for its final step and I'm hoping to have this project finished by the end of my internship on June 12th. Will the release be before then? Is there any way I could get Beta access to the combine feature?

3) Thanks! Fortunately though the distanceTo method works for my purposes as I'm only dealing with linear edges.

Message 8 of 13
casey.rogers
in reply to: casey.rogers

4) Given two planar adjacent faces, how can I tell via the API if they form a concave or a convex angle?

Message 9 of 13
casey.rogers
in reply to: casey.rogers

And yet another question, sorry to spam:

5) I have a design with a component that has several occurences. I'm trying to traverse the design to locate the proxy BRepBodies specifc to each occurence. Seeing as the occurence object doesn't have a BrepBodies property and the component object only returns the native object and not the proxies, how am I meant to access the proxies? ie, with reference to the image below, I want to retrieve m1:1/Body1 and m1:2/Body1 separately by accessing their independent proxies as opposed to their identical underlying native object.

asdf.PNG

Message 10 of 13
ekinsb
in reply to: casey.rogers

Answer to Question 5:

 

It's fairly easy to create a proxy of the body as you're traversing the assembly.  Below is an example of how to do this within the traversal.  For each occurrence it checks to see if the associated components has any bodies and if it does then for each body it creates a proxy of the body.  Any queries on the new body will take into account the occurrence transform.

 

if occ.component.bRepBodies.count > 0:
    for body in occ.component.bRepBodies:
        bodyProxy = body.createForAssemblyContext(occ)

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 11 of 13
ekinsb
in reply to: ekinsb

Answer to question 4:

You'll see that the Fusion measure command doesn't differentiate between the convex and convave and always reports the same angle for both.  This is easly done in the API by getting the normals from each face and getting the angle between them.  However, a colleague shared with me some additional logic you can apply to determine if the faces are convex or concave which uses the direction of the co-edges of the faces.  The script below demonstrates this.

 

import adsk.core, adsk.fusion, traceback
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        edge = ui.selectEntity('Select an edge', 'Edges').entity
        
        # Get the two faces connected by the edge and get the normal of each face.
        face1 = edge.faces.item(0)
        face2 = edge.faces.item(1)       
        ret = face1.evaluator.getNormalAtPoint(face1.pointOnFace)
        normal1 = ret[1]
        ret = face2.evaluator.getNormalAtPoint(face2.pointOnFace)
        normal2 = ret[1]
 
        # Get the angle between the normals.       
        normalAngle = normal1.angleTo(normal2)
        
        # Get the co-edge of the selected edge for face1.
        if edge.coEdges.item(0).loop.face == face1:
            coEdge = edge.coEdges.item(0)
        elif edge.coEdges.item(1).loop.face == face1:
            coEdge = edge.coEdges.item(1)

        # Create a vector that represents the direction of the co-edge.
        if coEdge.isOpposedToEdge:
            edgeDir = edge.startVertex.geometry.vectorTo(edge.endVertex.geometry)
        else:
            edgeDir = edge.endVertex.geometry.vectorTo(edge.startVertex.geometry)

        # Get the cross product of the face normals.
        cross = normal1.crossProduct(normal2)
        
        # Check to see if the cross product is in the same or opposite direction
        # of the co-edge direction.  If it's opposed then it's a convex angle.
        if edgeDir.angleTo(cross) > math.pi/2:
            angle = (math.pi * 2) - (math.pi - normalAngle)
            ui.messageBox('Angle: ' + str(angle * (180/math.pi)) + ', Convex')
        else:
            angle = math.pi - normalAngle
            ui.messageBox('Angle: ' + str(angle * (180/math.pi)) + ', Concave')        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 12 of 13
casey.rogers
in reply to: ekinsb

Thanks for all the help!

Is it okay with you if I use the code from your script in my add-in, with proper attribution of course?

Message 13 of 13
ekinsb
in reply to: casey.rogers

Anyone is welcome to re-use any code I post here and no attribution is necessary.  However, I've found it best to include a link in the comments of my code to where I originally found code to help in debugging later.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

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