Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MichPaule on June 04, 2024, 12:18:05 am

Title: Does EA_GetMenuState actually work in JavaScript?
Post 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
Title: Re: Does EA_GetMenuState actually work in JavaScript?
Post by: MichPaule on June 04, 2024, 05:13:10 pm
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?
Title: Re: Does EA_GetMenuState actually work in JavaScript?
Post by: Takeshi K on June 04, 2024, 06:16:37 pm
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,

Title: Re: Does EA_GetMenuState actually work in JavaScript?
Post by: Eve on June 05, 2024, 08:23:48 am
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)

Quote
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.
Title: Re: Does EA_GetMenuState actually work in JavaScript?
Post by: MichPaule on June 05, 2024, 03:26:27 pm
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
Title: Re: Does EA_GetMenuState actually work in JavaScript?
Post by: Eve on June 06, 2024, 08:46:36 am
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)