Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

create a parametric curves offset from python API?

kydU2N83
Observer

create a parametric curves offset from python API?

kydU2N83
Observer
Observer

Hi there, first time poster here.

 

Is it possible to create parametric sketch curve offsets (e.g., dimensioned via a UserParameter) via the API?

 

I went through the UI and created a quick (closed) sketch: 3 lines and an arc. Then I made a parametric offset from this shape, with the dimension "foo". Changing the user parameter worked as it should. I removed any auto-generated constraints (Horiz, Vert, Perpendicular) and then poked around with the sketch in a debugger session:

 
-> root
<adsk.fusion.Component; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::fusion::Component > *' at 0x7fa8a02f7a80> >
 
-> sketch = root.sketches.item(0)
-> sketch
<adsk.fusion.Sketch; proxy of <Swig Object of type 'std::vector< adsk::core::Ptr< adsk::fusion::Sketch > >::value_type *' at 0x7fa8a02eb1b0> >
 
-> sketch.geometricConstraints.count
1
 
-> sketch.geometricConstraints.item(0)
<adsk.fusion.OffsetConstraint; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::fusion::OffsetConstraint > *' at 0x7fa880bc7d20> >
 
-> offset_c = sketch.geometricConstraints.item(0)
-> offset_c.dimension
<adsk.fusion.SketchOffsetCurvesDimension; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::fusion::SketchOffsetCurvesDimension > *' at 0x7fa8a02c08d0> >
 
-> offset_dim = offset_c.dimension
-> offset_dim.parameter
<adsk.fusion.ModelParameter; proxy of <Swig Object of type 'adsk::core::Ptr< adsk::fusion::ModelParameter > *' at 0x7fa8a02c0990> >
 
-> offset_dim.parameter.expression
'foo'
 
So, my question is: how do I programmatically get a SketchOffsetCurvesDimension? The only APIs that I see take a float (Sketch.offset), or don't work on arcs/don't have the same behavior (SketchDimensions.addOffsetDimension). Is it possible to set this up?
 
Thanks much!
-tim

 

0 Likes
Reply
1,069 Views
3 Replies
Replies (3)

BrianEkins
Mentor
Mentor

You can use the Sketch.offset method to create a parametric office.  It's demonstrated in this sample script.

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-e20ca15a-fd06-11e4-aaf7-3417ebd3d5be

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

kydU2N83
Observer
Observer

Sorry, maybe my post wasn't clear. What I mean by "parametric" is an offset that is attached to a UserParameter. The Sketch.offset method you refer to takes a "double": http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-fe28f2e1-bfbf-4521-ac35-14d677d38441

 

In other contexts (e.g., a SketchArc's radius), you set up the geometry using a real value (e.g., a double), and then add a Constraint or a Dimension to it, which can take a string ValueInput. I don't see any equivalent method for offsets, except for SketchLine.

 

Does that make sense?

-tim

 

0 Likes

BrianEkins
Mentor
Mentor

It would be nice to have a "do-over" with this method because there are a couple of things that can be improved.  One is that it should take a ValueInput to define the offset so then you could supply the name of the existing user parameter.  The second is that it would be nice if it returned the model parameter that's created.

 

However, there is a workaround to both of these issues.  When you create the offset a model parameter is being created and we can get it by just getting the last model parameter in the collection.  Then you can edit it's expression so it's dependent on the user parameter you will have already created.

 

To see this in action you can use the sample I reference above with the following changes:

  1. Create a user parameter in the active design called "Offset".
  2. Comment out the line:
    #doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
  3. Add the following lines at the bottom

 

# Get the parameter controlling the offset from the parent component of the sketch.
param = sketch.parentComponent.modelParameters[sketch.parentComponent.modelParameters.count - 1]

# Set the value to an existing user parameter.
param.expression = 'Offset'

 

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