Book a Demo

Author Topic: Access to MDG tagged values in addin  (Read 4192 times)

GrahamL

  • EA User
  • **
  • Posts: 111
  • Karma: +2/-0
    • View Profile
Access to MDG tagged values in addin
« 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?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Access to MDG tagged values in addin
« Reply #1 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

GrahamL

  • EA User
  • **
  • Posts: 111
  • Karma: +2/-0
    • View Profile
Re: Access to MDG tagged values in addin
« Reply #2 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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Access to MDG tagged values in addin
« Reply #3 on: June 11, 2020, 12:55:41 am »
Well, you just added a new one. Find the existing and update that.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Access to MDG tagged values in addin
« Reply #4 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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Access to MDG tagged values in addin
« Reply #5 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.

GrahamL

  • EA User
  • **
  • Posts: 111
  • Karma: +2/-0
    • View Profile
Re: Access to MDG tagged values in addin
« Reply #6 on: June 11, 2020, 04:50:31 pm »
Thanks all working now - till the next time ;D

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Access to MDG tagged values in addin
« Reply #7 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.