Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: dgoetz on November 09, 2021, 10:37:41 pm
-
I have a problem assigning new value to a tagged value and then read it back using C#.
Executing this code fragment, "taggedValueRead" contains the value before assigning the "new" value.
I tried Update() and Refresh() calls, nothing helped.
If the element after execution is unselected in the model and then selected again, the tagged value contains the value "new". Therefore, the tagged value is changed.
Dieter
EA.Element element = iEA.GetContextObject as EA.Element;
EA.TaggedValue taggedValue = element.TaggedValues.GetByName("MDG::name");
if (taggedValue != null)
{
taggedValue.Value = "new";
taggedValue.Update(); element.Update(); element.Refresh(); // just to be sure
EA.TaggedValue taggedValueRead = element.TaggedValues.GetByName("MDG::name");
if (taggedValueRead != null)
{
iEA.TabWrite("value: " + taggedValueRead.Value); // -> outputs the old value
}
}
-
Try
element.TaggedValues.Refresh()
This will reload the tagged values collection from the database.
Geert
PS. I never use TaggedValues.GetByname as I'm never certain there aren't going to be two tagged values with the same name.
-
GetByName doesn't work on the qualified name of the tag, so unless you've actually set that as the name of the tag it will never return anything.
-
Hi Geert,
thanks - it works.
Hi Eve,
GetByName() works for me with qualified tag names.
What is the better method than TaggedValues.GetByname()?
Dieter
-
What is the better method than TaggedValues.GetByname()?
Loop over the TaggedValues collection and check the name.
Something like
For Each existingTag In element.TaggedValues
If existingTag.name = "CR" Then
Set taggedValue = existingTag
Exit For
end if
Next
In this case you are in control of what happens when you have multiple tagged values with the same name.
Geert