Book a Demo

Author Topic: Fail to add Tagged Value to attribute  (Read 4261 times)

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Fail to add Tagged Value to attribute
« on: May 21, 2008, 09:08:41 pm »
Hi all,

I need to add some tagged value to an attribute. I use below code to add the tagged value.. (using C#)

Code: [Select]
EA.Element elContainer = this.repository.GetElementByID(Int32.Parse(elementID));
EA.Attribute newAttribute = (EA.Attribute)elContainer.Attributes.AddNew("MyAttribute", "");

EA.AttributeTag attrTag = (EA.AttributeTag)newAttribute.TaggedValues.AddNew("TagName", "");
attrTag.Value = "TagValue";
attrTag.Update();

newAttribute.Update();
newAttribute.TaggedValues.Refresh();

elContainer.Update();
elContainer.Attributes.Refresh();
elContainer.Refresh();

But the tagged value doesn't appear on the Project Browser (even I have tried to close the model and reopen it, coz I though it was not well refreshed).
Where did I make the mistake? :-?

Cheers

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Fail to add Tagged Value to attribute
« Reply #1 on: May 21, 2008, 09:35:29 pm »
Your code is probably allright, but like many other things tagged values never appear in the project browser. You need to show the tagged value window (it's in the View menu) to see the tagged values belonging to the element which is selected in the project browser or on the active diagram.

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Fail to add Tagged Value to attribute
« Reply #2 on: May 21, 2008, 11:15:56 pm »
Sorry, I meant in the Tagged Value Window not in Project Browser.
Yes, I'm sure have checked it on the Tagged Value Window and there is nothing.

I have successfully added tagged value for an Element. But, not for the attribute.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Fail to add Tagged Value to attribute
« Reply #3 on: May 22, 2008, 09:33:21 am »
Kezia,

I would highly recommend that you run newAttribute.Update() before your create the new tagged value.  When creating a new object through automation, always run the object's Update() method before attempting to add anything to it's collection properties.

So something more like...

Code: [Select]
EA.Attribute newAttribute = (EA.Attribute)elContainer.Attributes.AddNew("MyAttribute", "");
newAttribute.Update();

EA.AttributeTag attrTag = (EA.AttributeTag)newAttribute.TaggedValues.AddNew("TagName", "");
attrTag.Value = "TagValue";
attrTag.Update();

newAttribute.TaggedValues.Refresh();

HTH.

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Fail to add Tagged Value to attribute
« Reply #4 on: May 22, 2008, 05:16:39 pm »
Hi Aaron,

Thanks for you tips. It's working now  :D

Cheers