Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Kezia on May 15, 2009, 05:07:42 pm
-
Hi all,
I created an element with stereotype XSDSimpleType with code below:
EA.Element newElement = (EA.Element)this.selectedPackage.Elements.AddNew("myElement3", "Class");
newElement.Stereotype = "XSDSimpleType";
newElement.Type = "string";
newElement.Update();
newElement.Refresh();
The code ran successfully and in project browser it showed only the name of element (without stereotype before the name).
when I double-clicked on the newly created element, element's name disappear and then it showed only the stereotype <<XSDSimpleType>> and no property dialog pops up.
And the other weird thing is, when I closed the project, and then opened it again, the element disapper. But by using code, I know the element is there but don't show up.
I have no idea what the problem is. When creating element which is NOT "XSDSimpleType" stereotyped, the code and the result will be ok.
Anyone can help me to figure out what is wrong? or did I miss something in the code?
Cheers,
Kristina
-
You probably need to save your new object (by calling Update) before setting the stereotype.
-
(I think) You can sometimes set a stereotype before you call Update(), but what Simon suggests is good EA programming practice.
The call to Refresh() looks odd. You should only refresh collections, not individual elements.
Update() is actually a function that returns a Boolean result; a return value of true indicates that the Update() was successful. It might be worth testing the result of this call. If false is returned you can use other calls--check the documentation--to learn more about the error.
-
Unfortunately, your suggestion doesn't work.
- I've tried to Update() the new element before setting stereoype.
- Ok, the Refresh() method looks odd, I've removed it.
- Both Update() method were successful, it returned true.
But the error symptom is still the same..
EA.Element newElement = (EA.Element)this.selectedPackage.Elements.AddNew("myElement4", "Class");
bool x = newElement.Update();
newElement.Stereotype = "XSDSimpleType";
newElement.Type = "string";
bool y = newElement.Update();
Unfortunately again, I can't find any documentation on EA Help related to setting XSDSimpleType stereotype on an element.
-
Does this page help you at all? XSDsimpleType is the third option in the list, and the third table in the topic.
http://www.sparxsystems.com/uml_tool_guide/xml_technologies/uml_profile_for_xsd.html
Perhaps also check whether case sensitivity is a problem - in your call, Simple should be simple?
-
Hi Kristina,
Remove the line (newElement.Type = "string")
Best,
Neo
-
Hi Kristina,
Also include the line:
newElement.Genlinks = "Parent=String;"
so the final code would be
EA.Element newElement = (EA.Element)repository.GetTreeSelectedPackage().Elements.AddNew("myElement3", "Class");
newElement.Stereotype = "XSDSimpleType";
newElement.Genlinks = "Parent=string;";
newElement.Update();
Best,
Neo
-
Hi Neo..
Perfect..!! ;D
I guess the "Parent=string" is for setting the type of XSDSimpleType..
Thank you very much for your help !! :)
== Finally I got the answer ==
Kristina