Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Viking on March 14, 2017, 09:44:57 pm
-
Hi together,
is there a way to use an If-Or-Statement within a shape script?
"if-else" is not an option, because then I would have to copy the script within the brackets (e.g. if (a=1) {do XY} else if (a=2) {do XY}). I need something like "if (a=1) else if (a=2) {do XY}".
Setting a variable inside the shape script could help me, but I think that this is not possible (e.g. if (a=1) {var1=1}; if (a=2) {var1=1}; if (var1=1) {do XY}).
Any suggestions? Many thanks in advance V.
-
Shapescript is dumb as bread. IF only accepts one HasProperty method as argument. No string comparison. No arithmetics.
q.
-
Shapescript is dumb as bread. IF only accepts one HasProperty method as argument. No string comparison. No arithmetics. q.
Really? I thought that the existing scripting languages were not good enough and it was necessary to invent a new one. Is that a misinformation?
-
Why take a proven, existing language, if you can invent a new one? Or even another one for transformations?
q.
-
Why take a proven, existing language, if you can invent a new one? Or even another one for transformations?
q.
This is a very good question. I don't know if we will find out the reason one day.
-
Why take a proven, existing language, if you can invent a new one? Or even another one for transformations?
Suggest that it's replaced with SVG, that's always fun :-)
-
Only if they consider including animated icons.
q.
-
Why take a proven, existing language, if you can invent a new one? Or even another one for transformations?
q.
The benefit is that it provides us (the consultants who know how to use those languages) with job security ;D
Geert
-
O.k. Back to the question. It seems to me that I have to copy the scrpt several times -> if (a=1) {do XY} else if (a=2) {do XY}.
Or is there a possibility to implement subroutines (Like the sub shapes)?
-
The first sentence in my first reply still stands.
q.
-
The first sentence in my first reply still stands.
q.
So there is no workaround. Many thanks for your answers.
-
Yes, the language is simplistic.
I've handled this is the past by reversing the logic.
if (a!=1) {
if (a!=2) {do XY}
}
-
I believe what qwerty is saying is that you cannot do text or value comparisons in ShapeScript. There is no "if ( a=1 )" syntax. There is only "if (hasproperty(a))"
-
Exactly. The polite way of stating ShapeScript's capabilities is what Simon said. I'm more that rude guy.
q.
-
Exactly. The polite way of stating ShapeScript's capabilities is what Simon said. I'm more that rude guy.
q.
So long as Simon meant "too simple to work properly" - which is the corect meaning of "simplistic". Simplistic is NOT a fancy way of saying "simple". There's a word for that - "simple"
Paolo
-
I believe what qwerty is saying is that you cannot do text or value comparisons in ShapeScript. There is no "if ( a=1 )" syntax. There is only "if (hasproperty(a))"
I thought the pseudo-code would make the issue easier to undertand. I did not. I am sorry.
I need someting like:
shape main
{
layouttype="border";
if(hasproperty("diagram.mdgtype", "BPMN1.0::Business Process") OR hasproperty("diagram.mdgtype", "BPMN2.0::Business Process") )
{
AddSubShape("Activity","center");
}
}
-
Yes, the language is simplistic.
I've handled this is the past by reversing the logic.
if (a!=1) {
if (a!=2) {do XY}
}
Could be that I do not understand the point. Could you translate this into my example, please?
shape main
{
layouttype="border";
if(hasproperty("diagram.mdgtype", "BPMN1.0::Business Process") OR hasproperty("diagram.mdgtype", "BPMN2.0::Business Process") )
{
AddSubShape("Activity","center");
}
else if(hasproperty(...)
{
...
}
}
-
No. There is no AND. There is no OR. Look at Simon's example how to code a work around for the AND. It's simple Boolean algebra and use of copy and paste.
q.
-
No. There is no AND. There is no OR. Look at Simon's example how to code a work around for the AND. It's simple Boolean algebra and use of copy and paste. q.
I was not asking for AND. I was asking for OR. If Simon's example reflects AND, than this is no solution for my issue. If Simon's example reflects OR, than I do not understand how to copy and paste it into my example.
-
In that case you might need to do something like
shape main
{
layouttype="border";
if(hasproperty("diagram.mdgtype", "BPMN1.0::Business Process")
{
...
}
else if(hasproperty(...)
{
...
}
if hasproperty("diagram.mdgtype", "BPMN2.0::Business Process")
{
AddSubShape("Activity","center");
}
else if(hasproperty(...)
{
...
}
}
That would means some duplicated code, but it would work. It would make things easier if we could use NOT, AND and OR, but where's the challenge then right ;D
Geert
-
In that case you might need to do something like
shape main
{
layouttype="border";
if(hasproperty("diagram.mdgtype", "BPMN1.0::Business Process")
{
...
}
else if(hasproperty(...)
{
...
}
if hasproperty("diagram.mdgtype", "BPMN2.0::Business Process")
{
AddSubShape("Activity","center");
}
else if(hasproperty(...)
{
...
}
}
That would means some duplicated code, but it would work. It would make things easier if we could use NOT, AND and OR, but where's the challenge then right ;D
Geert
This is what we are doing at the moment. But the issue is in the SubShapes where we are using a lot of code. And this code has to be dublicated several times.
-
It has been said more than once here, that there is no OR. There are also no functions/procedures. There is just COPY and PASTE. The way you do it is the only way. Capisce?
q.
-
You'll either need to duplicate the conditions or the bodies.
shape main
{
layouttype="border";
if(hasproperty("diagram.mdgtype", "BPMN1.0::Business Process")) {} else
{
if(hasproperty("diagram.mdgtype", "BPMN2.0::Business Process")) {} else
{
AddSubShape("Activity","center");
}
}
if(hasproperty("diagram.mdgtype", "BPMN1.0::Business Process"))
{
if(hasproperty("diagram.mdgtype", "BPMN2.0::Business Process"))
{
if(hasproperty(...)
{
...
}
}
}
}
Although I would just ignore the possibility of BPMN 1.0 diagrams. Make your life a bit easier.
So long as Simon meant "too simple to work properly" - which is the corect meaning of "simplistic".
I meant that the simplicity makes some things unnecessarily difficult. It works. Although you may argue that it doesn't because it doesn't offer some capabilities that you would like to see.
-
I meant that the simplicity makes some things unnecessarily difficult. It works. Although you may argue that it doesn't because it doesn't offer some capabilities that you would like to see.
Given that the OP is trying to do something that everyone advised him not to do, I think this whole conversation is down the rabbit hole anyway. :-)
-
It has been said more than once here, that there is no OR. There are also no functions/procedures. There is just COPY and PASTE. The way you do it is the only way. Capisce? q.
Many thanks, Thomas.
-
No. There is no AND. There is no OR. Look at Simon's example how to code a work around for the AND. It's simple Boolean algebra and use of copy and paste.q.
We are using AND and it works as intended :)
Yes, there is no OR or XOR in the way we need it.
Given that the OP is trying to do something that everyone advised him not to do, I think this whole conversation is down the rabbit hole anyway. :-)
I did not know that everybody told me. Many thanks for telling me.