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: 

Get centroid of face in world space

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
838 Views, 6 Replies

Get centroid of face in world space

Hi there,

 

I'm having trouble writing an add on in which I need the centroid of a face in world co-ordinates. It seems that any transformation that has been applied to the body is not taken into account. Is there a way to at least obtain the transform of a BRepBody once it has been moved? I could use this to transform the point to world space.

 

Alternatively is there a solution to obtaining vertices that are part of a body in world space?

Labels (3)
6 REPLIES 6
Message 2 of 7
goyals
in reply to: Anonymous

Is centroid property on BRepFace not returns the value in world coordinates? Please take a look at http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-801B5FF8-3BA8-48A0-8796-BBB329CDE1D0.



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 7
Anonymous
in reply to: goyals

I don't think so, when I run it on a body that has been moved, I get the same coordinates back as before the move.

Message 5 of 7
BrianEkins
in reply to: Anonymous

Position information from a BRepBody, and most objects, are returned relative to the coordinate system of the component that owns that entity.  I'm guessing you want to get the coordinate relative to the root component.  If the body owned by the root component, then it coordinates will always be in root coordinate space.  If you've created a new component and the body is in that component, coordinates for that body will be returned relative to that component's coordinate system.  There are a couple of ways to get the coordinate with respect to the root component.

 

Let's look at an example.

  1. Create a new assembly.
  2. Create a new component named "Test".  In the browser it will be listed as "Test:1" because it's the first instance of the component "Test".
  3. Add a box primitive to the new component.  In the browser, you should see it under the "Test:1" occurrence.
  4. Select "Test:1" in the browser and do a copy-paste operation to create a second occurrence of the component "Test".  It will show up in the browser as "Test:2".
  5. Move both "Test:1" and "Test:2" around in the assembly.

What we have now is the component named "Test" that contains a single BRepBody.  There are two occurrences that reference that component.  There's only one body but you're seeing two in the assembly.  Moving the occurrences around in the assembly doesn't affect the body or the component.  Through the API, if you get the BRepBody of the block and query coordinate information it will be returned relative to the "Test" component.  However, if the user selects a face on the body, a proxy of the BRepFace is returned.  The BRepFace proxy returns coordinate information as if the face exists in the root component. If you don't want the user to select the face, you can create a proxy by using the createForAssemblyContext method on the face. You need to pass in the occurrence you want to create the proxy relative to.  In the example above, there are two instances of the real face and you have to tell it which of the two you want to create the proxy for.

 

The other approach is to get the points in the component space and then apply the occurrence transform to the coordinate to get it in root coordinate space.  Create the proxy is easier.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 7
Anonymous
in reply to: Anonymous

Hello,

 

Thank you for your replies! The examples have helped me to get positions relative to moved components and understand occurrences better.

 

I'm actually going to have to apologize, I believe the centroids co-ordinates are returned in world space I just got confused because the units appear to be cm? Is this the default unit type for scripting in fusion 360?

 

Message 7 of 7
BrianEkins
in reply to: Anonymous

The internal units of Fusion are centimeters so that's what the API uses. You can read more about it here.

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-A81B295F-984A-4039-B1CF-B449BEE893D7

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

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report