Book a Demo

Author Topic: Problems with adding tagged values to elements, C#  (Read 3347 times)

Nik

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Problems with adding tagged values to elements, C#
« on: February 11, 2009, 03:02:14 am »
Hello!

I am trying to program an Add-In in C# which automatically adds two tagged values to every element in a selected package. I have tried it with following code, but if I execute the Add-In, no tagged values are added.

The code looks like:

EA.Package aPackage;
aPackage = Repository.GetTreeSelectedPackage();
                              
foreach(EA.Element theElements in aPackage.Elements)
{
    theElements.TaggedValues.AddNew("Estimate", "String");
    theElements.Update();
    theElements.TaggedValues.AddNew("PSP-Value", "String");
    theElements.Update();
}


I also wondered why there is no Method provided for initializing a
new TaggedValue with an specific value, so maybe the AddNew(...) Method may be not appropriate for dealing with new TaggedValues.

Maybe someone who has experience in adding and initializing new TaggedValues to Elements via Add-Ins/C# coding could help me.
Thanks beforehand,
                             Nik

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Problems with adding tagged values to elements
« Reply #1 on: February 11, 2009, 08:25:39 am »
The AddNew command returns a tagged value object.  You'll need to call update on that.  (And not necessarily the collection)

Nik

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Problems with adding tagged values to elements
« Reply #2 on: February 11, 2009, 07:28:35 pm »
Thanks for the tip! Making a new Variable of type EA.TaggedValue, assining the returned tagged value object and then calling update on that helped.

best regards, Nik