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

UserParameters - Automatic Update

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
MichaelT_123
550 Views, 8 Replies

UserParameters - Automatic Update

Hi TF360,

 

Following the recent update on the F360 Design& Validate side ...

 

Turn Automatic Update on and off to pause any updates to the model in the background when you make changes to the parameter table. Click Apply to manually update the model. Complex assemblies with parametric timelines recalculate with each change to the parameters. Turning off Automatic Updates will reduce computing time

 

... I wonder if the Automatic Update of the userParameter set will be exposed as the respective API function?

 

Regards

MichaelT

 

MichaelT
Labels (3)
8 REPLIES 8
Message 2 of 9
Amyoqzy
in reply to: MichaelT_123

I just searched the API documentation for that flag. Would indeed be nice to have this in the API too.

Message 3 of 9
BrianEkins
in reply to: Amyoqzy

If you experiment with this in the product, you'll see that it's a feature of the Parameters command and not a general setting. However, the API provided a new function a couple of releases ago that provides the same capabilities to the developer and I think in a more API-friendly way.  Check out the Design.modifyParameters method.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 9
MichaelT_123
in reply to: BrianEkins

Hi Mr Ekins,

 

Thank you for pointing it out!
How I missed this valuable new functionality?
Oops ... I know ... I too often refer to offline API documentation ... instead rummage for the new snowflakes in the clouds.

 

Regards

MichaelT

 

 

MichaelT
Message 5 of 9
MichaelT_123
in reply to: MichaelT_123

Hi TF360,

I have looked at the new:

returnValue = design_var.modifyParameters(parameters, values)
As per documentation returnValue
booleanReturns true if setting all of the parameters was successful. Setting multiple parameters is either all or none. If it fails to set any parameters, none of them are updated, and the method will return false.

In my opinion, and I also think many programmer practitioners, the information returned by the function is minimal, particularly in the case of process failure. How do you debug/control such a situation? Wouldn't it be natural and straightforward to return the index of failed parameter value change (or, let's say, -1 if there is a success)?

What about adding the option of allowing partial failure and/or returning the result as a boolean list instead?

Although adding modifyParameters() to API set is a good move, implementing this functionality leaves some ... discomfort.

Sincerely

MichaelT

MichaelT
Message 6 of 9
Amyoqzy
in reply to: BrianEkins

@BrianEkins Thank you for pointing this out.

 

I tried to implement my script using this method, but strangely, it didn't change any parameters in the design.

 

I use code like this. Preparing two arrays, one with the parameter objects and the other with the value inputs. Then I call the method with these two arrays.

parameters: list[adsk.fusion.UserParameter] = []
values: list[adsk.core.ValueInput] = []
for name in parameter_names:
parameters.append(user_parameter[name])
value_input = adsk.core.ValueInput.createByString(str(values[name]))
values.append(value_input)
self.design.modifyParameters(parameters, values)

 The code generates no exceptions, and `modifyParameters` returns `True`. 

 

If I change the code section to the original, where individual values are assigned. Everything works as expected:

for name in parameter_names:
user_parameter[name].expression = str(values[name])

 

So, most likely, I do something wrong. Is there somewhere a working example script?

Message 7 of 9
BrianEkins
in reply to: Amyoqzy

Here's a version of your test where I made it a little verbose to help me track down the problem. However, it's working for me. I used a test case of a triangle where the length of each side is controlled with a parameter. Making big changes to the size of the triangle wasn't possible before because the intermediate step of changing one of the values would cause the sketch compute to fail. Now it works because I can change them all at once. I named the parameters driving the dimensions Side1, Side2, and Side3.

 

Triangle.png

 

Here's the script, which is working for me.

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = adsk.fusion.Design.cast(_app.activeProduct)

        parameters: list[adsk.fusion.UserParameter] = []
        values: list[adsk.core.ValueInput] = []

        side1Param = des.allParameters.itemByName('Side1')
        side2Param = des.allParameters.itemByName('Side2')
        side3Param = des.allParameters.itemByName('Side3')
        parameters.append(side1Param)
        parameters.append(side2Param)
        parameters.append(side3Param)

        if side1Param.value - 3 < 0.0001:
            values.append(adsk.core.ValueInput.createByReal(8))
            values.append(adsk.core.ValueInput.createByReal(8))
            values.append(adsk.core.ValueInput.createByReal(8))
        else:
            values.append(adsk.core.ValueInput.createByReal(3))
            values.append(adsk.core.ValueInput.createByReal(3))
            values.append(adsk.core.ValueInput.createByReal(3))

        res = des.modifyParameters(parameters, values)    
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 8 of 9
Amyoqzy
in reply to: BrianEkins

@BrianEkins Thank you for the example!

Strange why this does not work for me. My code looks very similar. One difference is that I use strings with expressions and not real values. I will create a small example listing to see where the problem lies.

Message 9 of 9
BrianEkins
in reply to: Amyoqzy

It is strange. I also tried setting it with strings and it worked. Can you post a file and code that is failing? It seems something isn't working correctly.

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

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