Author Topic: Running javascript script from a menu item - how to?  (Read 2761 times)

Ribeye

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Running javascript script from a menu item - how to?
« on: March 28, 2022, 09:55:06 pm »
I have:

a) created some add-ins - they appear under Specialize -> Addins. Look good. The <<javascriptAddin>> class has both EA_GetMenuItems and EA_MenuClick, which are working fine.

b) written some javascript scripts using functions under Specialize -> Javascript Library. They are also running fine.

Now I want to execute my b) javascript scripts from by a) menu items.

How do you do this?

I have search everywhere for an answer with no luck. I tried syntax like

 !INC Local Scripts.EAConstants-JScript

as it is used b) javascripts, but this causes a) EA_MenuClick javascript to throw a syntax error
2)

 

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Running javascript script from a menu item - how to?
« Reply #1 on: March 28, 2022, 10:10:24 pm »
1. If you simply want to execute your script from the context menu, you can edit the script group type. The group type will determine the context menu's it show up in. (e.g. Project Brower, Diagram, ...)

2. !INC Local Scripts.EAConstants-JScript includes the script EAConstants-JScript in your script. This is nothing but the declaration of a bunch of constants. I'm not sure why you think that will somehow solve your problem.

Geert

Ribeye

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: Running javascript script from a menu item - how to?
« Reply #2 on: March 29, 2022, 01:00:13 am »
Yes, I get point 1): I put my Specialize->Tools->JavaScript javascript (called "validate") into a scripts group type which will determine where the is shown.

But I want to run the "validate" javascript from my add-in menu - not seeing that in group type options. So I put my "validate" javascript script into group type "Normal Group".

Then I want to call "validate" javascript script (that is in a "Normal Group") from a EA_MenuClick javascript of my plugin.

How to do that?

Re point 2) Presumably you need to include "validate" javascript in the EA_MenuClick javascript  some how. So I thought !INC might be a EA way of doing that, but it only seems to work in Specialize->Tools->JavaScript javascript .

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Running javascript script from a menu item - how to?
« Reply #3 on: March 29, 2022, 01:18:49 am »
If you want to execute a function from an existing script, you'll have to include that script (or copy the code in your add-in script)

I'm not sure if the add-in scripts support includes though.

Geert

Ribeye

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: Running javascript script from a menu item - how to?
« Reply #4 on: March 29, 2022, 01:37:13 am »
oh!

I will test "import" from the EA_MenuClick javascript.

If that does not work it would mean if I have a common javascript function that I want to use in lots of places I have to copy it lots of times.

Many thanks for your input Geert, very helpful.