Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: bITs.EA on April 04, 2016, 06:51:35 pm

Title: Shape Script : adding package contents compartment
Post by: bITs.EA on April 04, 2016, 06:51:35 pm
Hi

I've created a custom Shape Script, but now I want to add an extra compartment showing the "package contents" (if this is selected in the diagram properties)...

This is my current shape script, but I can't find the needed info in the user guide to add the deparment. Can someone help me, please?

Code: [Select]
shape main{

noshadow = "TRUE";
h_align = "center";
v_align = "center";

if(hastag("Macroprocess Type","Management"))
{
setfillcolor(0,204,255);
}
if(hastag("Macroprocess Type","Primary"))
{
setfontcolor(255,255,255);
setfillcolor(0,43,255);
}
if(hastag("Macroprocess Type","Supporting"))
{
setfillcolor(142,237,255);
}


startpath();

moveto(0,0);
//lineto(15,50);
lineto(0,100);
lineto(85,100);
lineto(100,50);
lineto(85,0);
lineto(0,0);

endpath();

fillandstrokepath();
printwrapped("#NAME#");

}
Title: Re: Shape Script : adding package contents compartment
Post by: Geert Bellekens on April 04, 2016, 07:06:18 pm
Hey Stijn,

This is the section in the user guide that deals with adding custom compartments:

http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/add_custom_compartments_to_ele.html (http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/add_custom_compartments_to_ele.html)

Geert
Title: Re: Shape Script : adding package contents compartment
Post by: bITs.EA on April 04, 2016, 07:15:15 pm
So if I understand well, I should add this under my main script and it should work?

Code: [Select]
//Add compartments for Child elements.
shape ChildElement
{
     //So set the compartment name to "Contents".
     SetCompartmentName("Contents");
   
     //Add the child elements name to the child compartment.
     AppendCompartmentText("#NAME#");
}

EDIT: Tested the above and no extra compartment in the element... What did I do wrong??
Title: Re: Shape Script : adding package contents compartment
Post by: bITs.EA on April 04, 2016, 11:13:06 pm
I've tried using the script below, but no extra compartment with package contents is shown. Only when I use the "DrawNativeShape()" command, it works. But I want to add a compartment to a custom shape... So what should I change to add a compartment to the custom shape below?

Code: [Select]
shape main{

noshadow = "TRUE";
h_align = "center";
v_align = "center";

if(hastag("Macroprocess Type","Management"))
{
//Blue color scheme
//setfillcolor(0,204,255);
//Grey / Orange color scheme
setfillcolor(200,200,200);
}
if(hastag("Macroprocess Type","Primary"))
{
//Blue color scheme
//setfontcolor(255,255,255);
//setfillcolor(0,43,255);
//Grey / Orange color scheme
setfillcolor(255,140,0);
}
if(hastag("Macroprocess Type","Supporting"))
{
//Blue color scheme
//setfillcolor(142,237,255);
//Grey / Orange color scheme
setfillcolor(225,225,225);
}

startpath();

moveto(0,0);
//lineto(15,50);
lineto(0,100);
lineto(85,100);
lineto(100,50);
lineto(85,0);
lineto(0,0);

endpath();

fillandstrokepath();
printwrapped("#NAME#");

//DrawNativeShape();
}

//Add compartments for Child elements.
shape ChildElement
{
     //So set the compartment name to "Contents".
     SetCompartmentName("Contents");
   
     //Add the child elements name to the child compartment.
     AppendCompartmentText("#NAME#");
}
Title: Re: Shape Script : adding package contents compartment
Post by: Geert Bellekens on April 04, 2016, 11:23:37 pm
I don't remember exactly how it worked anymore.
Wasn't there an example shapescript with a compartment?

http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/example_scripts.html (http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/example_scripts.html)

Yes, there is an example at the link above. That should hopefully help you further.

Geert
Title: Re: Shape Script : adding package contents compartment
Post by: qwerty on April 04, 2016, 11:39:07 pm
What you try is not possible. The native form is the only one that can display the content.

q.
Title: Re: Shape Script : adding package contents compartment
Post by: Geert Bellekens on April 04, 2016, 11:49:59 pm
Are you sure?

I don't see any DrawNativeShape in the example:

Code: [Select]
/ EDITABLE FIELD SHAPE
shape main
{
     rectangle(0, 0, 100, 100);
     addsubshape("namecompartment", 100, 20);
     addsubshape("stereotypecompartment", 100, 40);
     shape namecompartment
     {
               h_align = "center";
               editablefield = "name";
               rectangle(0, 0, 100, 100);
               println("name: #name#");
     }
     shape stereotypecompartment
     {
               h_align = "center";
               editablefield = "stereotype";
              rectangle(0, 0, 100, 100);
              println("stereotype: #stereotype#");
     }
}

Geert
Title: Re: Shape Script : adding package contents compartment
Post by: bITs.EA on April 04, 2016, 11:59:56 pm
Yes, you have 2 distinct scenarios for the shape script of an element:

1) Adding properties / attributes of the element itself to a shape.

This can be done using subshapes (like in your example). This applies to native & custom shapes.

2) Adding properties of child elements of the element. (eg. add the names of all the child elements of a package)

This can be done using "shape ChildElements{}" IF you use a native shape.
This cannot be applied to custom shapes.

Unfortunately, I want to show ChildElements in a custom shape...
Title: Re: Shape Script : adding package contents compartment
Post by: Eve on April 08, 2016, 02:57:55 pm
Custom shape scripts can't render either the built-in compartments or any child element compartments etc.

There's no call to "insert compartments into this position".

Geert's example isn't for compartments in this way. It's only rendering the name and stereotype as a subshape with the name "compartment".
Title: Re: Shape Script : adding package contents compartment
Post by: Geert Bellekens on April 08, 2016, 03:48:26 pm
Geert's example isn't for compartments in this way. It's only rendering the name and stereotype as a subshape with the name "compartment".
Hey, that's not my example, but one of the examples scripts from the manual.
Kind of misleading is these compartments aren't real compartments then ain't it?

Geert
Title: Re: Shape Script : adding package contents compartment
Post by: qwerty on April 08, 2016, 06:55:07 pm
Pretty well done then, if they even mislead you xD

q.