Javascript add-in to modify user parameters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I've been testing out writing a Javascript Add-in which would manipulate user params. Since it's a new environment I've started with the AddInSample javascript code which is bundled with Autodesk Fusion 360 and created new addIn with nearly identical sources to make the UI initialization work. The major modifications I've made are in the onInputChanged function. The current version of the source looks the following way:
var onInputChanged = function(args) {
console.log('onInputChanged', args, args.input, args.input.name, '=', args.input.value);
var name = args.input.name;
var expr = args.input.value;
try
{
var app = adsk.core.Application.get();
var design = app.activeProduct;
var userParams = design.userParameters
var p = design.userParameters.itemByName(name);
p.expression = ''+expr;
} catch (e) {
ui.messageBox(locStrings.FailedInInputChangedEvent + errorDescription(e));
}
};What I've been struggling with is the runtime behaviour of the code above. To begin with I've defined 2 user parameters and used them to dimension a rectangle in a sketch. When I edit a parameter in the UI of the add in what is happening is the following sequence of events which I've caught with the debugger breakpoint:
- onInputChanged function is called with the value from UI inputs
- The new value of parameter expression is being applied
- After onInputChanged function finishes previous user parameters values are being restored
All of these are illustrated in images I've attached:
- step1.png - before applying the new value the dimension in the upper edge of the screenshot is 10mm
- step2.png - after updating the parameter's expression new value is applied and the value of the dimension in the upper edge applies and is 20mm
- step3.png - after the function exits the dimension returns to 10mm
What I'm suspecting is that handling of the userParams manipulation is done in a temporary context/thread and thus it doesn't apply to the activeDocument/design context so it could be persisted. Does somebody maybe know how to persist the new expression value to the design?

