Book a Demo

Author Topic: Stereotype on packages  (Read 3844 times)

Dave Couture

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Stereotype on packages
« on: February 20, 2011, 02:26:52 am »
I'm working on an add-in that initialize packages, diagrams and elements based on their stereotype. Adding diagrams and elements with stereotype is working fine, but I'm not able to add a package with a stereotype.

I tried different options to set the package stereotype without any success  :-?.

The first easy one that wasn't working:

public EA.Package AddPackage(string name, string stereotype)
{
    if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name");

    Package package = (Package)this._package.Packages.AddNew(name, "Nothing");

    if (!String.IsNullOrEmpty(stereotype))
    {
        package.StereotypeEx = stereotype;
    }
    package.Update();
    this._package.Packages.Refresh();

    return package;
}


The second one that wasn't working to:

public EA.Package AddPackage(string name, string stereotype)
{
    if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name");

    Package package = (Package)this._package.Packages.AddNew(name, "Nothing");

    if (!String.IsNullOrEmpty(stereotype))
    {
        IDualPackage idualPackage = (IDualPackage)package;
        idualPackage.StereotypeEx = stereotype;
    }
    package.Update();
    this._package.Packages.Refresh();

    return package;
}


Am I missing something?

Strange that we could access the StereotypeEx property but it is not explain on the documentation (see http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/package_2.htm).

I'm stock since my add-in is based on stereotype to determine with initialization action to take based on the stereotype.

Thanks for helping.




stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: Stereotype on packages
« Reply #1 on: February 20, 2011, 08:45:31 am »
hi,
this is how it works for me:

Code: [Select]
EA.Package newTGGProject = (EA.Package)currentPackage.Packages.AddNew(tggProjectName, "");
newTGGProject.Update();
newTGGProject.Element.Stereotype = "TGGPackage";

currentPackage is the root package in the .eap file.
newTGGProject.Element is the element linked to the package.
each package in ea has a linked element.

stao
« Last Edit: February 20, 2011, 08:45:49 am by stao »

Dave Couture

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Stereotype on packages
« Reply #2 on: February 20, 2011, 01:49:40 pm »
Thanks!  :)