Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Hoefler1 on March 11, 2016, 08:17:25 pm

Title: Read/Write Stereotypes of an Element
Post by: Hoefler1 on March 11, 2016, 08:17:25 pm
Hey,
I want to set a certain Stereotype to each newly created element.
I use EA_OnPostNewElement and access the Element itself by
Code: [Select]
int ElementID = Int32.Parse(Info.Get("ElementID").Value);
EA.Element Element = Repository.GetElementByID(ElementID);
(This works fine)
In the User Guide it says for the Element Class:
Quote
StereotypeEx | String | Read/Write
                                   All the applied stereotypes of the element in a comma-separated list.
 
So I want to change this Attribute by assigning it to another String-Value. This shows no effect...
Someone know why?
Title: Re: Read/Write Stereotypes of an Element
Post by: Geert Bellekens on March 11, 2016, 08:25:01 pm
It should.

Have you called Update() after changing the value of StereotypeEx?

It might be helpful to post the code you are using.

Geert
Title: Re: Read/Write Stereotypes of an Element
Post by: Hoefler1 on March 11, 2016, 09:22:24 pm
Hello Geert,

Where and how do I call Update()?
Here's the code:
It should add every stereotype of the Package to the Element's. (I will add some if-clause to only adopt the suitable stereotypes)
Code: [Select]
public void EA_OnPostNewElement(EA.Repository Repository, EA.EventProperties Info)
        {
            int ElementID = Int32.Parse(Info.Get("ElementID").Value);
            EA.Element Element = Repository.GetElementByID(ElementID);

            EA.Package Package = Repository.GetPackageByID(Element.PackageID);
            string Stereotype = Package.StereotypeEx;

            Element.StereotypeEx += "," + Stereotype;
        }
Title: Re: Read/Write Stereotypes of an Element
Post by: Geert Bellekens on March 11, 2016, 09:43:22 pm
Code: [Select]
Element.Update();
That will save the changes you made to the database.

Geert

PS. Check for existing stereotype before adding "," otherwise you might get ",PackageStereotype" in the stereotype field. There are really nice functions for Split and Join that can handle those things for you.
Title: Re: Read/Write Stereotypes of an Element
Post by: qwerty on March 11, 2016, 11:25:40 pm
I just ran a test. When assigning "some,,more" the results are very strange (just try it yourself). If you assign ",somemore" the results are equally strange (you don't get rid of <<somemore>> in the GUI.

q.
Title: Re: Read/Write Stereotypes of an Element
Post by: Paolo F Cantoni on March 14, 2016, 10:41:47 am
I just ran a test. When assigning "some,,more" the results are very strange (just try it yourself). If you assign ",somemore" the results are equally strange (you don't get rid of <<somemore>> in the GUI.

q.
There's already a bug reported about the GUI not handling multiple stereotypes correctly in v12.x.  I'm not sure t's been fixed fully yet, but the latest version seems to behave better.

Paolo