Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: GrahamL on June 11, 2020, 12:11:52 am

Title: Access to MDG tagged values in addin
Post 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?
Title: Re: Access to MDG tagged values in addin
Post by: Geert Bellekens on June 11, 2020, 12:25:18 am
They are in EA.Element.TaggedValues
Nothing really special about them.

What is the exact issue?

Geert
Title: Re: Access to MDG tagged values in addin
Post by: GrahamL on June 11, 2020, 12:29:42 am
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
Title: Re: Access to MDG tagged values in addin
Post by: qwerty on June 11, 2020, 12:55:41 am
Well, you just added a new one. Find the existing and update that.

q.
Title: Re: Access to MDG tagged values in addin
Post by: Geert Bellekens on June 11, 2020, 01:15:31 am
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
Title: Re: Access to MDG tagged values in addin
Post by: qwerty on June 11, 2020, 02:28:49 am
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.
Title: Re: Access to MDG tagged values in addin
Post by: GrahamL on June 11, 2020, 04:50:31 pm
Thanks all working now - till the next time ;D
Title: Re: Access to MDG tagged values in addin
Post by: Eve on June 12, 2020, 10:25:54 am
Code: [Select]
                        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.