User Parameter in Extrude

User Parameter in Extrude

MartinCrawford-DTLD
Contributor Contributor
1,887 Views
3 Replies
Message 1 of 4

User Parameter in Extrude

MartinCrawford-DTLD
Contributor
Contributor

How do I add a user defined parameter to an extrusion. I have the parameter defined and I know how to do this when defining a sketch, I just can't seem to figure out how it works with an extrusion.

 

Thanks

 

0 Likes
1,888 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor

For the input argument that defines the length of the extrusion, create a ValueInput object as a string where the string is the name of the parameter.  Here's a simple example that assumes a parameter called "Length" already exists.

 

# Define that the extent the value of the parameter "Length".
distance = adsk.core.ValueInput.createByString('Length')

# Create the extrusion.
extrudes = rootComp.features.extrudeFeatures
ext = extrudes.addSimple(prof, distance, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 4

MartinCrawford-DTLD
Contributor
Contributor

Thanks for the quick response.

 

I may have not been clear in my request, this assigns the value from the User Defined Parameter, however what I was wanting to accomplish was to assign the Parameter to the extrusion, so later if I needed to update a value I could without re-running the script.

 

In the sketch, I did the following:

displayWidth = parameter.expression = 'DisplayWidth'
 
Is there an equivalent way with an extrusion.
 
Thanks
 
Message 4 of 4

Anonymous
Not applicable

I'm having the same issue, when referencing a user parameter inside a 'createByString' function, it's "flattened". The expression is computed correctly, but when I open the extrude feature from the timeline, the value it's extruded by is simply the result of the expression. I would expect it to function the same way as from inside the GUI, where you type 'Playfield_thickness - 0.25 in' into a value input, the reference is saved and updates to the parameter are reflected in the feature. 

 

For example, here's a snippet of the code I'm using for my extrude:

 

param_playfield_thickness_value = adsk.core.ValueInput.createByString("0.5 in")
design.userParameters.add("Playfield_thickness", param_playfield_thickness_value, "in", "The thickness of the playfield")

# ...

second_extrude_depth = adsk.core.ValueInput.createByString('Playfield_thickness - 0.25 in')
second_extrude = extrudes.addSimple(shelf_profile, second_extrude_depth, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

 

 

When 'Playfield_thickness' = 0.5 in, the extrude feature in the timeline simply lists 'Distance' as 0.25. 

 

Surely I'm using the parameter wrong? Otherwise it seems like this is a decent bug/oversight in the API?

 

Kyle

0 Likes