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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

User Parameter in Extrude

Message 1 of 4
1032 Views, 3 Replies

User Parameter in Extrude

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.




Message 2 of 4

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
Message 3 of 4

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.
Message 4 of 4

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?



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