16
Automation Interface, Add-Ins and Tools / Setting values to tags of stereotypes in C# - how to?
« on: April 27, 2022, 03:41:49 am »
I am successfully assigning stereotypes to elements I am creating in C#.
When it comes to setting values of tags that the stereotype has I am failing.
I copied code from https://sparxsystems.com/forums/smf/index.php?topic=6097.0 but it is creating new tags, not setting the tag values of the stereotype.
I cant find example code anywhere.
Here is that I have come to.
// https://sparxsystems.com/forums/smf/index.php?topic=6097.0
public static bool addTaggedValue(EA.Element elementParam, string tagName, string value)
{
TaggedValue tag = elementParam.TaggedValuesEx.GetByName(tagName);
if (tag == null)
{
TaggedValue element = elementParam.TaggedValuesEx.AddNew(tagName, value);
element.Value = value;
element.Update(); //must be executed in order to save new tagged value
elementParam.Update(); // is it needed?
elementParam.TaggedValues.Refresh();
String debugString = element.FQName; // always ""
return true;
}
tag.Value = value;
tag.Update();
elementParam.Update(); // is it needed?
elementParam.TaggedValues.Refresh();
return false;
}
When it comes to setting values of tags that the stereotype has I am failing.
I copied code from https://sparxsystems.com/forums/smf/index.php?topic=6097.0 but it is creating new tags, not setting the tag values of the stereotype.
I cant find example code anywhere.
Here is that I have come to.
// https://sparxsystems.com/forums/smf/index.php?topic=6097.0
public static bool addTaggedValue(EA.Element elementParam, string tagName, string value)
{
TaggedValue tag = elementParam.TaggedValuesEx.GetByName(tagName);
if (tag == null)
{
TaggedValue element = elementParam.TaggedValuesEx.AddNew(tagName, value);
element.Value = value;
element.Update(); //must be executed in order to save new tagged value
elementParam.Update(); // is it needed?
elementParam.TaggedValues.Refresh();
String debugString = element.FQName; // always ""
return true;
}
tag.Value = value;
tag.Update();
elementParam.Update(); // is it needed?
elementParam.TaggedValues.Refresh();
return false;
}