Author Topic: If-Or-Statement within Shape Scripts  (Read 17305 times)

Viking

  • EA User
  • **
  • Posts: 431
  • Karma: +2/-2
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #15 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");
   }
}

Viking

  • EA User
  • **
  • Posts: 431
  • Karma: +2/-2
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #16 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(...)
   {
      ...
   }
}


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #17 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.

Viking

  • EA User
  • **
  • Posts: 431
  • Karma: +2/-2
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #18 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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: If-Or-Statement within Shape Scripts
« Reply #19 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

Viking

  • EA User
  • **
  • Posts: 431
  • Karma: +2/-2
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #20 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.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #21 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.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8063
  • Karma: +118/-20
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #22 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.

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #23 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.  :-)

Viking

  • EA User
  • **
  • Posts: 431
  • Karma: +2/-2
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #24 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.

Viking

  • EA User
  • **
  • Posts: 431
  • Karma: +2/-2
    • View Profile
Re: If-Or-Statement within Shape Scripts
« Reply #25 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.