Are user parameters exposed through the API and/or will they be? It would be nice to do this for creating models that are easy for the end user to modify. The user parameters table is convenient to collect all important model parameters in one place and/or define relationships between parameters so they can be edited and redefined easily.
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
As you already reported in the other topic, you can access user parameters using the Design object. Model parameters can be accessed through the Component object. Here's a small sample that demonstrates accessing specific parameters by name and changing their values.
import adsk.core, adsk.fusion, traceback def main(): ui = None try: app = adsk.core.Application.get() des = app.activeProduct # Get the model parameter named "Height". heightParam = des.rootComponent.modelParameters.itemByName('Height') # Increase the value 25%. heightParam.value = heightParam.value * 1.25 # Get the user parameter named "Size". sizeParam = des.userParameters.itemByName('Size') # Set it using an expression. sizeParam.expression = "Height / 2" except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) main()
if lets say, multiple components (occurances) are present in a document, is there any way to get access to the parameters of each occurance via the API?
As you can see it is possible.
I achived it the following way:
- getting all user parameters
- traversing all components and store the ModelParameters for each
- searching the name of each UserParameter in the previously stored ModelParameters
- as result you get a list of all UserParameters for each component
You can use The userParameters object, which you get using the userParameters property on the Design object, supports an add method.