Book a Demo

Author Topic: Add Tagged Value to Connectors with an AddIn  (Read 4133 times)

MFruit

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Add Tagged Value to Connectors with an AddIn
« on: November 29, 2008, 02:50:01 am »
Hello,

I searched across the forum and EA User Guid but can't find the answer.

Reading TaggedValues (that have been put under EA, click on Association into the diagramm, then add value to "Connector Target" under TaggedValue Window) with my AddIn is OK. I'm parsing the collection of my SupplierEnd.TaggedValues element
Code: [Select]
foreach (IDualRoleTag cTag in con.SupplierEnd.TaggedValues)
{
      // Get Name and Value
     MessageBox.Show(cTag.Tag);
     MessageBox.Show(cTag.Value);
}

But creating with AddIn TaggedValue for an association target is not so easy. In fact i don't find it yet.

If i wasn't clear i want to do exactly the same in an AddIn what EA does across his User Interface (as describe higher).

Thx a lot !


Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Add Tagged Value to Connectors with an AddIn
« Reply #1 on: November 29, 2008, 05:09:54 am »
There's a VB sample on

http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/roletag.html

If you do just the same with C#, doesn't it work?

MFruit

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Add Tagged Value to Connectors with an AddIn
« Reply #2 on: December 01, 2008, 07:47:03 pm »
Yes, i saw this exemple, but it doesn't work or fit. You've right this is the good place because the documentation describe the RoleTag Attribute. And it is exactly what i want to do => specifie "BaseClass" as "ASSOCIATION_TARGET". Unfortunately, there is no exemple for this.

For information, i've done this exemple in C#, it works, but do nothing, i can't find added Tag later with the code describe in my post with the command:
Code: [Select]
foreach (IDualRoleTag cTag in con.SupplierEnd.TaggedValues)

MFruit

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Add Tagged Value to Connectors with an AddIn
« Reply #3 on: December 02, 2008, 12:52:05 am »
 [smiley=thumbup.gif] I found what was missing:

I had already created a connector.
Code: [Select]
Connector con = (Connector)e.Connectors.AddNew("", "Association");
con.ClientID = Source.ElementID;
con.SupplierID = Target.ElemenID;
con.Direction = "Source -> Destination";
con.SupplierEnd.Role = "MyRoleName";
con.SupplierEnd.Cardinality = "0..*";


The key to add TaggedValue later is to update the connector, otherwise an error occured:
Quote
"The fiels 't_taggedvalue.ElementID' can't contain a Null value because the Required property for this field is set to True. Enter a value in this field"

So put the following code line before addin RoleTag:
Code: [Select]
con.Update();
After addin TagValue for Role Association works perfectly:
Code: [Select]
RoleTag rTag = (RoleTag)con.SupplierEnd.TaggedValues.AddNew("", "");
rTag.BaseClass = "ASSOCIATION_TARGET";
rTag.Tag = "Attribute";
rTag.Value = "[Persistent]";
rTag.Update();
con.SupplierEnd.TaggedValues.Refresh();

//Can now get TaggedValue
foreach (IDualRoleTag cTag in con.SupplierEnd.TaggedValues)
{
    // Get Name and Value
    MessageBox.Show(cTag.Tag);
    MessageBox.Show(cTag.Value);
}

Thanks Frank for spending time to this post !
Hope that will help someone else.
« Last Edit: December 03, 2008, 06:18:14 pm by MFruitEA »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Add Tagged Value to Connectors with an AddIn
« Reply #4 on: December 03, 2008, 05:32:56 am »
This shows up in a lot of places in the EA API.

The general rule of thumb is that, before you have to call Update(), you can set most (but not all) properties that affect an entity (element, connector, whatever) as long as those parameters affect or refer to only that entity. [A possible exception is something like setting the supplier and client of a connector.]

If you want to set anything that affects another entity - such as adding something to a collection 'owned' by your entity, as in the present case - you need to Update() the entity first.

That's because EA does not actually create and store the entity in the database until the first call to Update(). [This also explains the exceptions; you need enough information to store valid records the first time.] In the EA schema, other entities that reference your newly created entity (such as tagged values owned by your entity) will need a meaningful ID (or something similar) in their data records. Until you've called Update() the first time there is no record to refer back to.

HTH, David
No, you can't have it!