User parameters Exosed in API?

User parameters Exosed in API?

dirktheeng
Advocate Advocate
2,993 Views
5 Replies
Message 1 of 6

User parameters Exosed in API?

dirktheeng
Advocate
Advocate

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.

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill
0 Likes
Accepted solutions (1)
2,994 Views
5 Replies
Replies (5)
Message 2 of 6

ekinsb
Alumni
Alumni
Accepted 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()

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 6

Anonymous
Not applicable

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?

0 Likes
Message 4 of 6

Anonymous
Not applicable

@Anonymous 

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

 

fusion05.PNG

0 Likes
Message 5 of 6

Anonymous
Not applicable

How can we create new User parameters through the API ?  (Seems not to be documented in the API manual?)

0 Likes
Message 6 of 6

BrianEkins
Mentor
Mentor

You can use The userParameters object, which you get using the userParameters property on the Design object, supports an add method.

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