Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MichPaule on June 04, 2024, 12:18:05 am
-
From what I understand JavaScript parameters always are passed by value.
However the last 2 parameters of EA_GetMenuState are defined as OUT (see https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/eaadd-insea_getmenustate.html).
Does this actually work?
In my Model Add-In experiments I didn't manage to make it work.
Has somebody had success using JavaScript?
TIA
Michael
-
Found it! :)
The OUT parameters isEnabled and IsChecked are objects instead of Booleans.
Reading/assigning values is accomplished via the object member val e.g. isEnabled.val = false;
Would be worth a remark in the documentation?
-
Hello Michael,
Including your solution, the Example model contains the basic information. It is helpful to start the Model-based addins.
(about 'isEnabled.val = false', we can find the EA_GetMenuState reception of the TypeInfo class in the example model.)
HTH,
-
Would be worth a remark in the documentation?
https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/modeladdins-code.html (https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/modeladdins-code.html)
Retrieving return values in JavaScript
When handling a reception for an event with OUT/INOUT parameters, values must be read and assigned using the .val attribute of those parameters.
For example, to set the value of the TagValue parameter on the EA_OnElementTagEdit event:
TagValue.val = "Hello World!"
In short, it's the way Javascript handles parameters. Effectively objects are passed by reference primitives are passed by value. That's not technically correct, but it's close enough to get me going.
If it was only that function then the comment could have been in the documentation for the broadcast. It's not.
-
Thanks a lot for the clarification, Eve!
I would not have searched for the info exactly in that place but maybe it's only me...
Michael
-
Which is the perennial problem of writing documentation. You can't document anything where everyone will look. (Partially because at least half don't look at all)