Shape scripts(color of an element with conditions)

298 views
Skip to first unread message

Jokew

unread,
Jun 26, 2015, 4:25:17 AM6/26/15
to sparx-enterprise-archite...@googlegroups.com
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

[original message]

qwerty

unread,
Jun 26, 2015, 4:56:01 AM6/26/15
to sparx-enterprise-archite...@googlegroups.com
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.

[original message]

Jokew

unread,
Jun 26, 2015, 5:17:03 AM6/26/15
to sparx-enterprise-archite...@googlegroups.com
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! :)

[original message]

qwerty

unread,
Jun 26, 2015, 6:46:40 AM6/26/15
to sparx-enterprise-archite...@googlegroups.com
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:
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.

[original message]

Bellekens@localhost Geert Bellekens

unread,
Jun 26, 2015, 7:06:01 AM6/26/15
to sparx-enterprise-archite...@googlegroups.com

4A4C5E494F423B0 wrote:
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 nee more info on how to make EA Adding you can visit my page Writing EA Add-ins (http://bellekens.com/writing-ea-add-ins/)

Geert

[original message]

M@localhost Simon M

unread,
Jun 28, 2015, 7:46:26 PM6/28/15
to sparx-enterprise-archite...@googlegroups.com

7C7A687F79740D0 wrote:
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.

[original message]

Jokew

unread,
Jun 29, 2015, 4:56:29 AM6/29/15
to sparx-enterprise-archite...@googlegroups.com
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:
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:
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:
selectedElement.Update();


I'ts solved now, thank you guys!  :)

[original message]

Jokew

unread,
Jun 29, 2015, 5:06:30 AM6/29/15
to sparx-enterprise-archite...@googlegroups.com
Yeah just realized and made the edit as you wrote your reply :)
Thx again

[original message]

qwerty

unread,
Jun 29, 2015, 5:06:56 AM6/29/15
to sparx-enterprise-archite...@googlegroups.com
I don't see the final selectedElement.Update()

q.

[original message]
Reply all
Reply to author
Forward
0 new messages