Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Paolo F Cantoni on February 03, 2017, 12:31:51 pm
-
Not having a lot of luck (which seems to be what is required when writing shapescripts) getting Compartments to work.
Trying to read the Help and other posts in the Forum, it seems:
- You can't create compartments for custom scripts
- You can only create compartments for Child Elements and Related Elements
- You can't create compartments ad-hoc even for nativeshapes
Is that correct?
Could some kind soul post a WORKING (preferably with v13) compartment enhanced shape script?
I tried some shown in the Help, I got a ChildElement script to work - though not as I expected, but I can't get the RelatedElement script to work at all.
What "secret sauce" am I missing?
-
1. Yes, they work for native shapes (that otherwise draw compartments) only.
2-3. Shape scripts only allow the definition of those two types. However, there is an add-in call that allows an add-in to define ad-hoc compartments. However, if you decide to use it you need to manage caching of the data yourself. It is called with every draw so you will turn your experience to sludge if you try looping through anything in the API.
I suspect your related element script is failing because the related elements are already on the diagram. There is also visibility options for each compartment type that you define.
-
[SNIP]
I suspect your related element script is failing because the related elements are already on the diagram. There is also visibility options for each compartment type that you define.
Nope,
Deleted from the diagram and still no joy. Where else to look?
Can you make the example work?
Paolo
-
I remember also that I tested the related element. I found that a good sleep, a nice day and some coffee helped to get it working. And, as you mentioned, a good portion of luck :-\
q.
-
So I'm trying to get this to work again... qwerty's suggestion didn't work - although the espresso was very nice.
So can anybody explain why this code (taken almost directly from the example page) doesn't work at all?
shape main
{
if(hasproperty("rectanglenotation","0")) //Icon Form
{
drawnativeshape();
}
else
{
drawnativeshape();
}
}
shape RelatedElement
{
SetCompartmentName("RelatedElements");
AppendCompartmentText("appended text");
//Check if the current connector being processed is a Realization
if(HasProperty("Connector.Type", "Realization"))
{
//Only display this compartment if the related element we
//are checking is the target of the connector that has this
//shape scripts element as the source
if(HasProperty("Element.IsTarget"))
{
//If the element is an interface, display it in
//'realizedInterfaces' compartment
if(HasProperty("Element.Type", "Interface"))
{
SetCompartmentName("realizedInterfaces");
AppendCompartmentText("#Element.Name#");
}
}
}
//Check if the current connector we are processing has a
//dependency type.
if(HasProperty("Connector.Type", "Dependency"))
{
//Check if the element we are currently checking is
//the target of the current connector.
if(HasProperty("Element.IsTarget"))
{
//Set the compartment Name
SetCompartmentName("dependsOn");
if(HasProperty("Element.Stereotype", ""))
{
AppendCompartmentText("??No Stereotype set");
}
else
{
AppendCompartmentText("«#Element.Stereotype#» ");
}
AppendCompartmentText("#Element.Name#");
}
}
}
I have three elements on the diagram one with a Relaization to the interface and a dependency to another (stereotyped) element.
-
You got me thinking, but...
I tried this example from the help shape RelatedElement
{
//Check if the current connector we are processing has a
//dependency type.
if(HasProperty("Connector.Type", "Dependency"))
{
//Check if the element we are currently checking is
//the target of the current connector.
if(HasProperty("Element.IsTarget"))
{
//Set the compartment Name
SetCompartmentName("dependsOn");
if(HasProperty("Element.Stereotype", ""))
{
}
else
{
AppendCompartmentText("«#Element.Stereotype#»");
}
AppendCompartmentText("#Element.Name#");
}
}
} where you should see dependent classes. It did not work. I seem to remember that one of the Sparxians mentioned some Feature Visibility check box which appeared only under certain circumstances. But I can't find that again.
I probably tried with another one from the examples. Anyhow, this is a mine field.
q.
P.S. I got this now to work again:
shape ChildElement
{
//Check if a child element has the property stereotype, if so set
//the compartment name to Properties.
if(HasProperty("stereotype", "property"))
{
SetCompartmentName("Properties");
}
//Check if the child element has a public scope and if so add the +
//symbol to the child compartment.
if(HasProperty("scope", "public"))
{
AppendCompartmentText("+");
}
//Add the child elements name to the child compartment.
AppendCompartmentText("#NAME#");
}I had to remove the contained element from the diagram which made the compartment visible. Also this one showed Properties as new check box in Feature Visibility.
-
Thanks, qwerty,
I, too, got the Child element stuff to work. Like you, I found I had to remove the child from the diagram in order to get the compartment to show. However, once it was visible, I could put the child element back and retain the compartment - pure EAUI?
Anyway, at least it's not personal that the related elements aren't working. Can a Sparxian, or anyone else, please show us all how to do this?
Paolo
-
[BUMP]
Is it really this hard? Do I need to submit a formal support request to get an answer?
Paolo
-
Formal support request submitted!
If, and when, I get a working example, I'll post it here.
Paolo