Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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 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:
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?
-
It should.
Have you called Update() after changing the value of StereotypeEx?
It might be helpful to post the code you are using.
Geert
-
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)
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;
}
-
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.
-
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.
-
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