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: 

Having trouble with API, may be a bug

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
brad.bylls
226 Views, 5 Replies

Having trouble with API, may be a bug

I am creating a mold making add-in and found some problems I don't know how to overcome.

I have attached a video to show the problems in question.

If you need to see the code for the bushing, I posted it in my last post a few days ago.

Thank you for any help.

Brad Bylls
5 REPLIES 5
Message 2 of 6
BrianEkins
in reply to: brad.bylls

An overview needs to be written that discusses how sketches work.  I think you're making some reasonable assumptions that aren't actually true.

 

You're having the user select the face for the bushing and then I assume you're creating a sketch on that face and then using the selection point as the location to draw geometry in the sketch.  If that's true, you're making the assumption that the coordinate system the selection point is returned in is the same as the coordinate system for the sketch.  That isn't usually true.

 

When you select the face and get the coordinate of the selection back, that point is returned with respect to the root coordinate system.  If you turn on the display of the construction geometry in the "Origin" folder of the root component that will show you the origin and orientation of the root coordinate system.

 

Each sketch has it's own coordinate system and is entirely independent of the root coordinate system.  The only case where they're guaranteed to be the same if when you create a sketch on the XY construction plane.  When using Fusion interactively, you don't really care because you're positioning geometry relative to other geometry.  However, when using the API, you're explicitly positioning geometry and it's location in model space is important.

 

When you edit a sketch there are some indications of its coordinate system.  A grid is shown with a dot indicating the origin (0, 0, 0) of the sketch coordinate system.  The red line going through the origin is the X axis and the green line is the Y axis.  Sketches are 3D and the Z axis can be inferred using the right-hand rule and crossing the X into the Y.  The problem is that what you're seeing doesn't indicate which direction is positive for the X and Y directions so it's not possible to know the positive directions just by looking at the sketch and because of that you don't which direction is the positive Z.  I believe when you create a sketch on a face, the Z direction of the sketch will always be pointing away from the solid the face is part of. 

 

SketchCoord2.png

 

 

Now that we've clarified that each sketch has it's own coordinate system it's important to know that the geometry you draw in that sketch is relative to the sketch coordinate system.  If I draw sketch circle at (0, 0, 0) in the example above, it will be positioned directly over the origin point.  Let's say I have a 3D point that I got from when the user selected the face the sketch was created on.  That point is in model space but I want to draw the circle at that location.  I can do that by getting a coordinate in sketch space that is in the same location relative to model space.  You can do that by using the Sketch.modelToSketchSpace method. You can then use that point to create the circle.

 

If you want to better visualize the coordinate system of a sketch, I've attached a small script that will display the coordinate system of the selected sketch.  Run the script a second time to remove the graphics.

 

SketchCoord3.png

Good luck.

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 6
brad.bylls
in reply to: BrianEkins

Thanks Brian.

I have asked the question before and nobody has ever mentioned sketch.modelToSketchSpace.

I will try and work that out.

What about the other problem?

When trying to create the bushing it is selecting other profiles other than those in the sketch.

Is that related to the modelToSketchSpace problem?

I hope so, it will kill two birds with one stone.

Thanks again.

Brad Bylls
Message 4 of 6
brad.bylls
in reply to: BrianEkins

OK

I got the sketch on the face at the selection point. That solves that problem. Thank you.

However, it is still selecting the outer edges of the face as the profile and not the sketch geometry for the profile.

Brad Bylls
Message 5 of 6
BrianEkins
in reply to: brad.bylls

I think I answered this in response to your other post, but the answer is to use Sketches.addWithoutEdges instead of Sketches.add

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

sketches.addWithoutEdges did the trik.

All is well and working great.

Thank you so much for your help.

I am learning that there is a lot hidden in plain sight if you just look for it, if you know what to look for.

Brad Bylls

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