Author Topic: Shape scripts(color of an element with conditions)  (Read 1284 times)

Jokew

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Shape scripts(color of an element with conditions)
« on: June 26, 2015, 06:11:11 pm »
Hi!

I am relatively new to Enterprise Architect and I am having trouble changing the color of an element (A business function in this case (archimate 2.0)).

I want the color of the element to depend on how many relations it has. I want to visualize some sort of heatmap so that you can se which elements has the most relations easily (e.g few realtions would be green and a moderate amount of relations would be yellow and a vast amount of relations would be red).

Is there anyway to do this using shape scripts? If not, is there anyway to do this at all?

I would be forever grateful if anyone could assist me in this or point me in the right direction.

Regards Jokew

qwerty

  • EA Guru
  • *****
  • Posts: 9205
  • Karma: +140/-132
  • I'm no guru at all
    • View Profile
Re: Shape scripts(color of an element with conditi
« Reply #1 on: June 26, 2015, 06:42:47 pm »
It's possible, but (very) difficult. So the simple answer would be: no, not possible.

The complicated (condensed) answer: you need to modify the shape script for that Archimate element, call an add-in to count the # of relations and change the color of the body.

Another way could be to run a script to do the same. This is feasible (indeed rather easy) if the Archimate element allows manual color changes.

q.

Jokew

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Shape scripts(color of an element with conditi
« Reply #2 on: June 26, 2015, 07:00:14 pm »
Okey so it is possible!
I really want this to work so I will try it the hard way if I have to. When you say add-in, you mean I should call a third-party extension from the shape script?


Quote
Another way could be to run a script to do the same. This is feasible (indeed rather easy) if the Archimate element allows manual color changes.

This script you are talking about here, it is a Jscript (or VB or Java i guess) that you can run on the entire project? (sorry I am really new to EA) Can I access elements and make changes to them using the script?

Thx for the answer, I will continue my research a little wiser! :)

qwerty

  • EA Guru
  • *****
  • Posts: 9205
  • Karma: +140/-132
  • I'm no guru at all
    • View Profile
Re: Shape scripts(color of an element with conditi
« Reply #3 on: June 26, 2015, 08:38:12 pm »
Actually there are two places which are difficult to tackle. The first is the modification of the original shape script. This is not really recommended (I can't talk much about copyright and such stuff...) but you have all resources at hand. The script is stored in the original MDG, coded as base64 in one attribute of the element and then the decoded data is a zip which contains the script. Now if you do the reverse you have your own script instead of the original one. Try this first, it's quite tricky. And don't count on any support from Sparx.

Second is the add-in. You need to write your own add-in that will do the relations-count-magic and return it as a string you can use to encode the color. This might turn out to get cumbersome as shape script has very, very  limited algorithmic capabilities. So you will likely need to limit the colors to a handful of hard coded values and not a "dynamical" color. I.e. you need to code
Code: [Select]
if hasproperty('addin:myRelations', '1') { ... } for each level (the '1' might tell the add-in to look for 1-3 connectors, a '2' for 4-6 and so on)

You might want to look at Geert's EA-Matic for the add-in stuff.

q.
« Last Edit: June 26, 2015, 08:39:12 pm by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8030
  • Karma: +183/-22
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Shape scripts(color of an element with conditi
« Reply #4 on: June 26, 2015, 08:51:24 pm »
Quote

You might want to look at Geert's EA-Matic for the add-in stuff.

q.

In this case the EA-Matic won't be of any help since you need a new operation, and EA-Matic only forwards the existing events to the scripting environment.

But if you need more info on how to make EA Adding you can visit my page Writing EA Add-ins

Geert
« Last Edit: June 26, 2015, 09:12:50 pm by Geert.Bellekens »

Simon M

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6279
  • Karma: +52/-5
    • View Profile
Re: Shape scripts(color of an element with conditi
« Reply #5 on: June 29, 2015, 09:34:28 am »
Quote
Actually there are two places which are difficult to tackle. The first is the modification of the original shape script. This is not really recommended...
It's also unnecessary in most circumstances.

You can extend an ArchiMate stereotype, and call DrawParentShape from your shape script after setting a color. This scenario of colouring a profile element is expected to work, although if the parent shape script explicitly sets a colour there's nothing you can do. I just checked a couple of ArchiMate shape scripts though and they don't appear to.

Personally, I would run a script as needed. Manually initially, but if required I would create a scheduled task to run a script over the model.
« Last Edit: June 29, 2015, 09:38:02 am by simonm »
Simon

support@sparxsystems.com

Jokew

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Shape scripts(color of an element with conditi
« Reply #6 on: June 29, 2015, 06:41:36 pm »
Thank you guys! I really feel like I am getting somewhere. I have managed to identify the number of connectors of an element via a JScript. I am now trying to change the appearance with SetAppearance like this:

Code: [Select]
var selectedElement as EA.Element;
selectedElement = Repository.GetElementByID(6);
selectedElement.SetAppearance(1,0,2);

But no luck  :-/
Nothing is happening to the element. I know which one it is since I also got this on sys.out

Code: [Select]
Session.Output("The number of connectors to "+ selectedElement.Name + " is: " + selectedElement.Connectors.Count);
I as said before I am really new to this and I am probably missing/not understanding half of what i see.

EDIT:
I forgot to update the element!
Code: [Select]
selectedElement.Update();
I'ts solved now, thank you guys!  :)
« Last Edit: June 29, 2015, 06:53:38 pm by Jokew »

qwerty

  • EA Guru
  • *****
  • Posts: 9205
  • Karma: +140/-132
  • I'm no guru at all
    • View Profile
Re: Shape scripts(color of an element with conditi
« Reply #7 on: June 29, 2015, 06:53:27 pm »
I don't see the final selectedElement.Update()

q.

Jokew

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Shape scripts(color of an element with conditi
« Reply #8 on: June 29, 2015, 06:54:17 pm »
Yeah just realized and made the edit as you wrote your reply :)
Thx again