Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: GrahamL on June 11, 2020, 12:11:52 am
-
Hi
My MDG has several tagged values defined for various elements for example "Desc".
These show up in a model containing one of these elements under a tab in the properties named after my MDG.
So far so good
I now need to access these in an addin but dont seem to be able to find a way in order to set them.
How can I do this?
-
They are in EA.Element.TaggedValues
Nothing really special about them.
What is the exact issue?
Geert
-
Here is an extract from my addin
EA.Element e = selectedPackage.Elements.AddNew("Context", "GSNProfile::Context");
EA.TaggedValue t = e.TaggedValues.AddNew("ID", "string");
t.Value = "xx";
t.Update();
e.Update();
selectedPackage.Update();
This does add a 'normal' tagged value for ID
However my MDG also has a tagged value called ID that appears in a separate tab on the properties window. It is this value that I want to set
-
Well, you just added a new one. Find the existing and update that.
q.
-
Indeed. The tagged values that belong to the stereotype are added automatically.
You might need to update() your element first though. (and possibly even reload it, I'm not sure)
Geert
-
No updates needed. Just loop through the existing tagged values and find the one named ID. With that TV (you got via GetAt) set the Value (or Notes if it's a memo) and Update it. That should update the right one.
Note that you should have only MDG-defined TVs. A mix with "normal" TVs created manually calls for trouble.
q.
-
Thanks all working now - till the next time ;D
-
EA.Element e = selectedPackage.Elements.AddNew("Context", "GSNProfile::Context");
EA.TaggedValue t = e.TaggedValues.AddNew("ID", "string");
t.Value = "xx";
t.Update();
e.Update();
selectedPackage.Update();
You may end up with issues with this code (or code similar to it) because it adds tagged values to the element before it is saved. I suspect because it's a profile element it may save it in the background, but I wouldn't be comfortable relying on that.
The Update call on the package seems to be unnecessary.