Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: SvenK on April 29, 2013, 10:25:34 pm
-
Hello,
is it possible to include scripts during runtime? In JScript you have to do
!INC foo.bar
However, neither of the following works:
if (something)
{
!INC foo.bar
}
eval("!INC foo.bar")
-
AFAIK EA uses '!INC' to include the actual script -prior to feeding it to a scripting enigne-, so language constructs like 'eval' wouldn't work.
But what are you trying to achieve by this?
-
But what are you trying to achieve by this?
I want to include some files only once.
Assume a script A creates a variable myvariable= new Object().
Another script B adds something to this variable: myvariable.number=10
If at another place script A is again included, myvariable is overwritten...
While writing this, I think I may introduce some kind of include-guard to solve the problem.
-
EA will not include the same script twice, so in your example if you include B in a script X, and subsequently A in the same script X, than this second include of A is ignored and the changes made in B will be visible to X.
If you have several scripts that share 'myvariable' as a common global variable only declare the global variable in A and either create/initialize the variable in the script you know will run first, or have each script that uses it check for existence first, like so:
!inc A
...
if (myvariable == undefined){
myvariable= new Object()
}
myvariable.number=10
...
-
EA will not include the same script twice, so in your example if you include B in a script X, and subsequently A in the same script X, than this second include of A is ignored and the changes made in B will be visible to X.
I wasn't aware of that. So my concerns were if superfluous. Thanks for the clarification.