Book a Demo

Author Topic: Shapescript show values in a comma separated list  (Read 5661 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Shapescript show values in a comma separated list
« on: October 31, 2020, 12:44:51 am »
I have this stereotype on a connector that has 5 boolean tagged values
Create, Update, Delete, Load, and Determine.

Now I want to show the ones that are true on the diagram as a sort of constraint.
So if Update = True, and Determine = True, I want to show {Update, Determine}

But I'm struggling a bit on how to implement such a thing in shapescript.
Below is the best I could come up with. It works, but if feels like it's written by an 8 year old who just learned about IF/THEN/ELSE (plus I'm and I'm very happy there aren't 8 or 10 tags)

Does anyone know a more intelligent way to get the same result (or can assure my that I'm not THAT thick :-[)

Code: [Select]
shape middleBottomLabel
{
if (HasTag("Create", "True"))
{
if (HasTag("Update", "True"))
{
if (HasTag("Delete", "True"))
{
if (HasTag("Load", "True"))
{
if (HasTag("Determine", "True"))
print("{Create, Update, Delete, Load, Determine}");
else
print("{Create, Update, Delete, Load}");
}
else if (HasTag("Determine", "True"))
print("{Create, Update, Delete,  Determine}");
else
print("{Create, Update, Delete}");
}
}
else if (HasTag("Delete", "True"))
{
if (HasTag("Load", "True"))
{
if (HasTag("Determine", "True"))
print("{Create, Delete, Load, Determine}");
else
print("{Create, Delete, Load}");
}
else if (HasTag("Determine", "True"))
print("{Create, Delete, Determine}");
else
print("{Create, Delete}");
}
else if (HasTag("Load", "True"))
{
if (HasTag("Determine", "True"))
print("{Create, Load, Determine}");
else
print("{Create, Load}");
}
else if (HasTag("Determine", "True"))
print("{Create, Determine}");
else
print("{Create}");
}
else if (HasTag("Update", "True"))
{
if (HasTag("Delete", "True"))
{
if (HasTag("Load", "True"))
{
if (HasTag("Determine", "True"))
print("{Update, Delete, Load, Determine}");
else
print("{Update, Delete, Load}");
}
else if (HasTag("Determine", "True"))
print("{Update, Delete , Determine}");
else
print("{Update,  Delete}");
}
else if(HasTag("Load", "True"))
{
if (HasTag("Determine", "True"))
print("{Update, Load, Determine}");
else
print("{Update, Load}");
}
else if (HasTag("Determine", "True"))
print("{Update, Determine}");
else
print("{Update}");
}
else if (HasTag("Delete", "True"))
{
if (HasTag("Load", "True"))
{
if (HasTag("Determine", "True"))
print("{ Delete, Load, Determine}");
else
print("{ Delete, Load}");
}
else if (HasTag("Determine", "True"))
print("{Delete, Determine}");
else
print("{Delete}");
}
else if (HasTag("Load", "True"))
{
if (HasTag("Determine", "True"))
print("{Load, Determine}");
else
print("{ Load}");
}
else if (HasTag("Determine", "True"))
print("{Determine}");
else
print("");
}

Geert
« Last Edit: October 31, 2020, 04:39:28 pm by Geert Bellekens »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Shapescript show values in a comma separated list
« Reply #1 on: October 31, 2020, 01:13:34 am »
That's what I recently meant by "poor, poor" language. Not your fault.

q.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Shapescript show values in a comma separated list
« Reply #2 on: October 31, 2020, 10:40:40 am »
That's what I recently meant by "poor, poor" language. Not your fault.

q.
+1

Shapescript could be SO MUCH MORE!

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: Shapescript show values in a comma separated list
« Reply #3 on: November 02, 2020, 08:54:33 pm »
Agree re limitations of shapescript language. Has anyone tested to see if the newish model add-ins work in a shapescript ? Standard add-ins do - so i'd hope model add-ins do as well. If they do then calling a model addin that prepares your string should perform ok - given its just string manipulation, not looking up loads of data etc.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Shapescript show values in a comma separated list
« Reply #4 on: November 03, 2020, 12:15:47 am »
Has anyone tested to see if the newish model add-ins work in a shapescript ?

I have, and they do. It's not a practice I would recommend though.

For one thing it's probably pretty easy to crash EA this way -- mutual recursion and whatnot. Not to mention that the power of having stuff in-model is also a weakness: the model can be modified after deployment.

But more importantly, the whole Model Add-In feature feels very much like a dead end to me. I think it's more likely than not that a version or two down the line it will be quietly deprecated, EA style. Which means leaving it incomplete with a couple of glaring showstopper bugs in there, and when users complain tell them some other feature is now the flavour of the month preferred solution, while leaving the documentation in place, making it look like the feature is main stream and fully supported. (For reference, see Required/disabled Technologies.)

If they do then calling a model addin that prepares your string should perform ok - given its just string manipulation, not looking up loads of data etc.

I think not. EA launches a separate process (sscripter.exe) for a Model Add-In (one for each or one for all, haven't tested -- for that matter, is it even possible to run more than one Model Add-In at a time?). I don't see how you can get anything remotely approaching acceptable performance this way.
By contrast, a DLL Add-In's code executes within the EA process, and even then, more than a dozen instances of a shape script Add-In call in one diagram is unusable.

So I'd say yes on the Add-In option to solve this problem, but no to the Model Add-In as an alternative. If the thing has to work in the wild, anyway. For a concept demo, I guess it could be OK.

Shapescript could be SO MUCH MORE!

Yes indeed. Why not make it an extension of (a subset of) SVG, with a couple of macros to access the model data?


/Uffe
« Last Edit: November 03, 2020, 12:18:11 am by Uffe »
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Shapescript show values in a comma separated list
« Reply #5 on: November 03, 2020, 03:42:34 am »
That SVG-path has been suggested before by others (can't recall who). The reason for Sparxians to have two ears is that the sound coming into one ear can leave through the other one.

q.