Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Viking on March 14, 2017, 09:44:57 pm

Title: If-Or-Statement within Shape Scripts
Post 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.
Title: Re: If-Or-Statement within Shape Scripts
Post by: qwerty on March 14, 2017, 10:51:57 pm
Shapescript is dumb as bread. IF only accepts one HasProperty method as argument. No string comparison. No arithmetics.

q.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 15, 2017, 12:09:20 am
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?
Title: Re: If-Or-Statement within Shape Scripts
Post by: qwerty on March 15, 2017, 01:59:45 am
Why take a proven, existing language, if you can invent a new one? Or even another one for transformations?

q.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 15, 2017, 03:28:17 am
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.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Glassboy on March 15, 2017, 12:50:03 pm
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 :-)
Title: Re: If-Or-Statement within Shape Scripts
Post by: qwerty on March 15, 2017, 09:08:09 pm
Only if they consider including animated icons.

q.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Geert Bellekens on March 15, 2017, 11:22:35 pm
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
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 16, 2017, 01:09:30 am
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)?
Title: Re: If-Or-Statement within Shape Scripts
Post by: qwerty on March 16, 2017, 01:29:18 am
The first sentence in my first reply still stands.

q.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 16, 2017, 04:36:53 am
The first sentence in my first reply still stands.
q.

So there is no workaround. Many thanks for your answers.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Eve on March 16, 2017, 08:47:04 am
Yes, the language is simplistic.

I've handled this is the past by reversing the logic.

if (a!=1) {
   if (a!=2)   {do XY}
}
Title: Re: If-Or-Statement within Shape Scripts
Post by: WarrenKenyon on March 16, 2017, 09:36:39 am
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))"
Title: Re: If-Or-Statement within Shape Scripts
Post by: qwerty on March 16, 2017, 10:44:10 am
Exactly. The polite way of stating ShapeScript's capabilities is what Simon said. I'm more that rude guy.

q.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Paolo F Cantoni on March 16, 2017, 10:58:00 am
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
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 16, 2017, 05:52:47 pm
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");
   }
}
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 16, 2017, 06:03:36 pm
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(...)
   {
      ...
   }
}

Title: Re: If-Or-Statement within Shape Scripts
Post by: qwerty on March 16, 2017, 07:59:25 pm
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.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 16, 2017, 08:05:30 pm
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.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Geert Bellekens on March 16, 2017, 10:27:51 pm
In that case you might need to do something like
Code: [Select]
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
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 16, 2017, 11:54:23 pm
In that case you might need to do something like
Code: [Select]
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.
Title: Re: If-Or-Statement within Shape Scripts
Post by: qwerty on March 17, 2017, 10:22:04 am
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.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Eve on March 17, 2017, 03:07:24 pm
You'll either need to duplicate the conditions or the bodies.

Code: [Select]
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.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Glassboy on March 20, 2017, 01:55:09 pm
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.  :-)
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 20, 2017, 11:13:27 pm
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.
Title: Re: If-Or-Statement within Shape Scripts
Post by: Viking on March 20, 2017, 11:20:14 pm
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.