Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: Modesto Vega on October 23, 2019, 04:23:09 am
-
Is it possible to change the appearance of an element depending on whether it belongs to the current package or not?
Could something like this be achieved using a shape script or some other means?
-
An External addin or script can do this.
Please refer below for more details on Automation
https://sparxsystems.com.au/enterprise_architect_user_guide/14.0/automation/automation_interface.html (https://sparxsystems.com.au/enterprise_architect_user_guide/14.0/automation/automation_interface.html)
Arsh
-
An External addin or script can do this.
Please refer below for more details on Automation
https://sparxsystems.com.au/enterprise_architect_user_guide/14.0/automation/automation_interface.html (https://sparxsystems.com.au/enterprise_architect_user_guide/14.0/automation/automation_interface.html)
Arsh
I know Sparx well to have guessed that. I was hoping for more specific answers and not such a generic answer, pity it ain’t a blank cheque :)
-
I am by no means an expert in Shape Scripts, or scripts of any kind, but a question comes to mind.
What would you identify as the 'current Package'? Say you have a diagram under Package A, and the diagram contains elements from Package A and Package B. If you are looking at the diagram itself, the current Package would be A, but once you start focusing on the external elements the current Package would be Package B.
I can see a Shape Script operating on HasProperty(Package, Package A) to apply the script appearance to elements owned by Package A, but I'm not sure how you would feed the 'current' Package name in there.
-
I guess that "current package" is that where the diagram is located. You will likely need an add-in to determine that and deliver it to the shape script.
q.
-
I think indeed there is no need for an add-in function as some shapescripts already indicate the name of the package if it is another package as the package owning the diagram.
Geert
-
Thanks RoyC, Qwerty & Geert.
I guess that "current package" is that where the diagram is located. You will likely need an add-in to determine that and deliver it to the shape script.
q.
Qwerty, indeed guessed correctly what I meant with “current package”.
I think indeed there is no need for an add-in function as some shapescripts already indicate the name of the package if it is another package as the package owning the diagram.
Geert
Could somebody please remind me, if it is possible to write a decorative shape script - i.e., one that does not change the default shape but instead changes such things as some of its visual properties? For example, I don’t really need to change how a class is displayed, just, for the shake of clarity, change its background colour to light grey if it does not belong the current package, if the class is not located on the same diagram as the diagram.
-
You can use something like
SetPenColor(0,0,255);
DrawParentShape(); I haven't tested that. Just a good guess. Using a decoration would also work.
Though I have no idea how to get the "current package" info. Geert seems to know.
q.
-
You can use something like SetPenColor(0,0,255);
DrawParentShape(); I haven't tested that. Just a good guess. Using a decoration would also work.
Though I have no idea how to get the "current package" info. Geert seems to know.
q.
I don't know how, but I see that classes only show their package when they are from a different package as the owner of the diagram (depending on the settings) and I seem to remember seeing something like that in the example shapescripts.
Geert
-
I was hoping that something like the following code will do it but it does not.
shape main{
if (hasproperty("packagepath"))
{
SetFillColor(210,210,210);
}else{
SetFillColor(255,255,255);
}
DrawParentShape();
}
What I found in v13 is as follows:
- All elements have both a packagename and a packagepath
- The packagename and the packagepath return the same values [Note: this looks like a bug in v13 but have not tried the same with v15.]
- There is no diagram.packagepath property available
-
When you search packagepath in the (13.5) "help system" you get 4 hits where 3 lead to nowhere and one to just an example. So there is no documentation for it. Means: it can't be a bug. Sparx speak.
q.
-
I think you are almost there.
From the example script on in the manual https://www.sparxsystems.com/enterprise_architect_user_guide/15.0/modeling/example_scripts.html (https://www.sparxsystems.com/enterprise_architect_user_guide/15.0/modeling/example_scripts.html) I recon you need the following test:
if (hasproperty ("packagepath", ""))
{
SetFillColor(210,210,210);
}
else
{
SetFillColor(255,255,255);
}
Here's the full example script:
// SHOW THE NAME OF THE OWNING PACKAGE WHEN THE ELEMENT
// IS USED ON A DIAGRAM NOT IN THAT PACKAGE, AND THE
// DIAGRAM PROPERTIES 'SHOW NAMESPACE' OPTION IS SELECTED.
shape main
{
layouttype= "border";
v_align= "CENTER";
h_align= "CENTER";
ellipse (0, 0, 100, 100);
printwrapped ("#name#");
addsubshape ("path", "S");
shape path
{
v_align= "top";
h_align= "center";
if (hasproperty ("packagepath", ""))
{
}
else
{
printwrapped ("(from #packagepath#)");
}
}
}
Geert
-
Thanks Geert, on v13 the code below works. Having the 'Show Namespace' option on the diagram selected does not appear to do anything. I find where "SetFillColor(210,210,210);" counter intuitive.
shape main
{
layouttype= "border";
v_align= "CENTER";
h_align= "CENTER";
if (hasproperty ("packagepath", ""))
{
SetFillColor(255,255,255);
}
else
{
SetFillColor(210,210,210);
}
rectangle (0, 0, 100, 100);
printwrapped ("#name#");
}
While this does not always work, it works on most entities but not in all.
shape main{
if (hasproperty ("packagepath", ""))
{
SetFillColor(255,255,255);
}
else
{
SetFillColor(210,210,210);
}
DrawParentShape();
}
I will try on v15 later this week.
-
Just an update on v15, this works fine irrespective of whether the 'Show Namespace' option on the diagram is selected or not.
shape main{
if (hasproperty ("packagepath", ""))
{
SetFillColor(255,255,255);
}
else
{
SetFillColor(210,210,210);
}
DrawParentShape();
}
-
Nice
Geert