Author Topic: Read/Write Stereotypes of an Element  (Read 7214 times)

Hoefler1

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Read/Write Stereotypes of an Element
« 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?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13241
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Read/Write Stereotypes of an Element
« Reply #1 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

Hoefler1

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Read/Write Stereotypes of an Element
« Reply #2 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;
        }
« Last Edit: March 11, 2016, 09:25:27 pm by Hoefler1 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13241
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Read/Write Stereotypes of an Element
« Reply #3 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.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Read/Write Stereotypes of an Element
« Reply #4 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.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8595
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Read/Write Stereotypes of an Element
« Reply #5 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
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!