Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Jayson on May 03, 2022, 07:13:15 pm
-
Hi all
Auto Colouring
When I apply a legend to a diagram and set the Auto Colour option ON, Sparx changes the colour of all applicable elements and when I set the Auto Colour option OFF, Sparx returns the colours of all elements to their previous state.
My question is whether Sparx expose this functionality for each element? Can programmatically do the same thing using a plug in?
That is:
1. Set the colour of elements based on some custom criteria, and
2. Revert the colour of the elements back to the original colour.
I realise in #2 I could set the element back to its default colour, but what if the user has changed the colour to something other than the default colour?
Filter
In a similar vein, is it possible to programmatically filter elements/connectors from a plug in?
Cheers
Jays :-)
-
The legend functionality is not exposed by the API.
If you want to achieve the same thing, you'll have to either put an actual legend on the diagram (and maybe remove it later) or build a similar functionality.
That would mean remembering the original color before you change it, and then later on reset to the original color.
Same thing for the filters I'm afraid.
Geert
-
You can script changes, e.g. diagramObject.SetStyleEx("BCol",colourDefault) to set the background colour (just to help I have defined colourDefault as -1 in my code. A positive number will set the colour to the number specified (RGB as a decimal - it's easiest if you create helper functions to the hard work of converting individual RGB values into one number!). So you could colour your elements (and you can also set the colour of connectors) using a script based on other parameters.
You might need to add a custom property (tagged value is probably a good option) to record any non-default colour to return the diagram to previous colours.
-
You might need to add a custom property (tagged value is probably a good option)
Tagged values live on elements, and the color is a property of a DiagramObject.
I'm not sure tagged values are the best option here, more so because they are visible to the user.
Geert
-
Geert is correct (he always is) ;) about there being no access to legends within the API.
However I have successfully created a script that creates a Legend (or Legends) on a selected diagram. Honestly, its a horrible task. The legend info is held as a rather nasty ; delimited string in t_xref, and the colour for the element / connector is not held as an RGB value, rather it appears to be some unique number that EA has obtained from the RGB. It looks like a simple Integer value for an RGB, but using the "standard" RGB to Integer method does not appear to yield the correct colour!
To get the correct legend info I had to create a legend manually, then examine t_xref, to get the info settings which I then put into my script which adds the entry into t_xref using a SQL INSERT statement.
The above is not a trivial task, but it can be done with a great deal of effort. Updating an existing entry in t_xref with a new info would involve working out the magic EA integer for the new RGB value, creating the legend info string and the using a SQL UPDATE to update t_xref.
Not for the faint hearted.
Best of luck
Phil
-
Hey Phil
Thanks for that.
Yep, I spent some of yesterday unpicking Legends in t_xref and t_object and you are right its not pretty.
The problem I am facing however is that I want to apply some custom logic (not supported by Legends or Filters).
Therefore, what I want to be able to do is:
* Temporarily change the colours to something else programmatically and then revert them back to what they were (which might not be the default), and/or
* Temporarily change the visibility of elements and connectors and then back to what they were.
Geert is correct (I'm shocked! ;-) ) that I could store the old colours and then re-apply them afterwards.
But with regards to filtering, I can find a connector visibility property easy enough but NOT element visibility.
Cheers
Jays :-)
-
I don't think you can make an element invisible.
You can only delete (and later restore) a diagramObject
Geert
-
Thanks Geert, yeah I thought that was the case.