Author Topic: Is it possible to start a script from a diagram?  (Read 17393 times)

Thomas Arnbjerg

  • EA User
  • **
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Is it possible to start a script from a diagram?
« on: February 09, 2024, 09:21:09 pm »
Is there a way to launch a script from a diagram? - e.g. a link in a diagram in a report package.

I often need to run a script before generating a report and it would be easier visualize this by including the invocation in the report packages somehow.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Is it possible to start a script from a diagram?
« Reply #1 on: February 09, 2024, 10:38:02 pm »
If you set the script group to "Diagram" you can execute the script from the context menu of the diagram.

Not sure if that answers your question though.

Geert

PDC

  • EA User
  • **
  • Posts: 90
  • Karma: +4/-0
  • Systems Engineer
    • View Profile
Re: Is it possible to start a script from a diagram?
« Reply #2 on: February 15, 2024, 12:13:52 am »
If you set the script group to "Diagram" you can execute the script from the context menu of the diagram.

well that's helped me out if not OP, thanks!
Phil

steverumsby

  • EA User
  • **
  • Posts: 28
  • Karma: +3/-0
    • View Profile
Re: Is it possible to start a script from a diagram?
« Reply #3 on: February 15, 2024, 09:38:17 pm »
Is there a way to launch a script from a diagram? - e.g. a link in a diagram in a report package.

I often need to run a script before generating a report and it would be easier visualize this by including the invocation in the report packages somehow.
There isn't as far as I know. As Geert said you can add the script to a "Diagram" group and then run it from the context menu, but that's not a nice UX (the "Scripts" menu isn't at the top level, and it has no structure so if you have lots of diagram scripts it can be hard to find the one you are looking for). For relatively quick scripts that you want to always run you can use a scriptlet, but if the script takes a while, or you don't want it to always run when you open a diagram, that doesn't work.

There are some cases where I'd like to have a button on the diagram that runs a script. I don't know of a way to do that - is there one?

Steve.

Thomas Arnbjerg

  • EA User
  • **
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Re: Is it possible to start a script from a diagram?
« Reply #4 on: February 17, 2024, 12:01:34 am »
Thanks for the responses. I'll look at the scriptlet option.

Elpis

  • EA User
  • **
  • Posts: 42
  • Karma: +6/-0
  • Make MDA/MBSE vital.
    • View Profile
Re: Is it possible to start a script from a diagram?
« Reply #5 on: February 17, 2024, 12:49:20 am »
[...] For relatively quick scripts that you want to always run you can use a scriptlet, but if the script takes a while, or you don't want it to always run when you open a diagram, that doesn't work.

There are some cases where I'd like to have a button on the diagram that runs a script. I don't know of a way to do that - is there one?

Scriptlet is executed automatically on the diagram loading/opening, or manually by Run Script context menu option. So solution is to avoid execution of functional code on first (automatic) run, in scriplet like below (trics explained next):

Code: [Select]
function Scriptlet1() {
if ( ! theElement.IsSpec )
{
Session.Output( `Scriptlet1 first (automatic, on diagram load) run.` );
theElement.IsSpec = true;
}
else {
Session.Output( `Scriplet1 next (manual) run.` );
  // functional code goes here
};
};

Scriptlet1();

The trick for recognizing first run and flagging next runs, is by use of Element.IsSpec property (of the script element itself). The property is deliberately chosen, as it is not used since UML 2 and maintained in EA only for backward compatibility, with default value of false. So it is set to false on scriptlet element load (i.e. on diagram load) and flipped to true on first scriptlet execution (automatic). And since changes to the property are not saved by scriptlet to model database, it is again false on next diagram load/reload.
In effect, functional code is to be executed only on-demand, by Run Script menu option, and not automatically on diagram opening.

 

shimon

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Re: Is it possible to start a script from a diagram?
« Reply #6 on: February 18, 2024, 04:19:50 pm »
I like that trick.
Thanks,
Shimon

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Is it possible to start a script from a diagram?
« Reply #7 on: February 18, 2024, 09:07:27 pm »
I don't get it. What's the point of using a scriptlet, if you don't want it to run as a scriptlet but as a regular script?

Why not use a normal script?

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8063
  • Karma: +118/-20
    • View Profile
Re: Is it possible to start a script from a diagram?
« Reply #8 on: February 19, 2024, 10:38:37 am »
I don't get it. What's the point of using a scriptlet, if you don't want it to run as a scriptlet but as a regular script?

Why not use a normal script?
It's not even going to work. As soon as you (or anyone) loads the diagram and doesn't manually run the script it's going to force the behavior on for the next time the diagram loads. It just means that you have to run the script twice instead of once.

Elpis

  • EA User
  • **
  • Posts: 42
  • Karma: +6/-0
  • Make MDA/MBSE vital.
    • View Profile
Re: Is it possible to start a script from a diagram?
« Reply #9 on: February 28, 2024, 02:16:07 am »
I don't get it. What's the point of using a scriptlet, if you don't want it to run as a scriptlet but as a regular script?

Why not use a normal script?

An original question was:
Quote
"Is there a way to launch a script from a diagram? [...]"
and it referred to running a script specific to 'that' one diagram.
So scriptlet came to a view, as @steverumsby noticed inconveniences of using 'normal' script in that context:
Quote
"As Geert said you can add the script to a "Diagram" group and then run it from the context menu, but that's not a nice UX (the "Scripts" menu isn't at the top level, and it has no structure so if you have lots of diagram scripts it can be hard to find the one you are looking for)."