Book a Demo

Author Topic: ShapeScript - print - addin  (Read 6201 times)

z.kadlec

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
ShapeScript - print - addin
« on: January 17, 2012, 11:11:21 am »
Dear all,

in shape-script documentation, in the section Display Element/Connector Properties in the help of EA (Standard UML Models->Define Modelling Language -> MDG Technology SDK -> Shap Script -> Write Scripts -> Display Element/Connector Properties...)

you can find:

"Properties for Element Shape Scripts
  
  • addin (value returned from an Add-In)
"

What does it mean? Would it be a way, how to put my own values into Shape Script?

I was not successful asking Uncle Google nor EA.Forum...

Thanks for any experience/example/explanation...

Zden[ch283]k
« Last Edit: January 17, 2012, 11:58:02 pm by z.kadlec »

z.kadlec

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: ShapeScript - print - addin
« Reply #1 on: February 22, 2012, 05:41:35 pm »
Well - it is as easy, as possible, thank to Sparx !!!  :)

The answer form them is:


-------------------

Hello Zdenek,

Sorry for the delay.

The "addin" property in shape scripts can be used to call a function provided by a custom EA add-in and print the string value returned by the add-in.


Enterprise Architect exposes an ActiveX / COM automation interface, allowing you to write an external application or Add-In to extend and automate Enterprise Architect functionality.
 
For more information on the automation interface (including full API reference), please refer to the help file included with Enterprise Architect.  The following link is to the online HTML version of this documentation:
http://www.sparxsystems.com/enterprise_architect_user_guide/9.0/automation/theautomationinterface.html
Some code samples are included in the installation directory with Enterprise Architect.  Additional code samples to help get started with writing EA add-ins can be found under the Resources area of the Sparx Systems website and on the EA Community web site.
http://www.sparxsystems.com/resources/developers/autint.html
http://community.sparxsystems.com/

Within your add-in you need to have a public function with an appropriate method signature that returns a string value. E.g. (C#)

public string GetValueForShape(EA.Repository Repository, string eaGuid, object theParams)

For example, your add-in function might return an element's name, stereotype, and alias in a single string...

Code: [Select]
     public string GetValueForShape(EA.Repository repository, string eaGuid, object theParams)
      {
            //Convert the parameters passed in into a string array.
            string[] args = (string[])theParams;
            
            //Get the element calling this addin
            EA.Element element = repository.GetElementByGuid(eaGuid);
            string ret = "";
            //Create the name modified element name
            if(args.Length > 0 && element != null)
            {
                  ret += element.Name;
                  
                  for(int i = 0; i < args.Length; i++)
                  {
                        if(args[i] == "Stereotype")
                              ret += " " + element.Stereotype;
                        
                        if(args[i] == "Alias")
                              ret += " " + element.Alias;
                  }
            }
            
            return ret;
      }
To call this function from a shape script would look like:

Code: [Select]
shape main
{
  //Draw the rect
  rectangle(0,0,100,100);
  //Replace CS_AddinFramework with your addin name and GetValueForShape with the function name you wish to call in your addin.
  print("#ADDIN:CS_AddinFramework, GetValueForShape, Stereotype, Alias#"); }

Best regards,
 
Aaron Bell
Sparx Systems Pty Ltd

z.kadlec

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: ShapeScript - print - addin
« Reply #2 on: February 24, 2012, 09:00:11 pm »
May be it would be useful for someone other -

Syntax for the IF clause to test return from ADDIN:

Code: [Select]
if (HasProperty("#ADDIN:CS_AddinFramework, getUseAliasIfAvailAble,Stereotype,Alias#","1"))
{
      println("Diagram si using Alias");
}
else
{
     print("Diagram is using Names");
}