Author Topic: How can I INSERT / UPDATE a tag value using EA API  (Read 9482 times)

dangel

  • EA User
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
How can I INSERT / UPDATE a tag value using EA API
« on: September 05, 2015, 08:38:20 am »
Is there any SDK explains how can I update some tagged value Types  in my Enterprise Architect Project, using API C# coding

Thanks
« Last Edit: September 05, 2015, 08:48:36 am by dangel »

dangel

  • EA User
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #1 on: September 05, 2015, 10:00:01 am »
I did the following code but no effects on EA Tagged Value Types

            EA.TaggedValue XX = new TaggedValue();
            XX.Name = "XX";
            XX.Notes = "ZZ";
            XX.Value = "AZ";
            XX.SetAttribute("XX", "ZZ");
            XX.Update();
=======================================
an error occurred , no results :(

« Last Edit: September 05, 2015, 10:05:12 am by dangel »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13240
  • Karma: +553/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #2 on: September 05, 2015, 03:57:08 pm »
You cannot create tagged values like that. You have to add it to an element.

Code: [Select]
EA.TaggedValue MyTaggedVal = MyElement.TaggedValues.AddNew("XX","");
Geert

dangel

  • EA User
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #3 on: September 05, 2015, 11:17:38 pm »
Thanks for your replay, I am developing an EA-Tool in order to extract some information from EA.Repository, but I want to insert new Tagged Value Types to the  repository not only to the elements, and later on I will call a function to link that Tagged Value to all elements in my diagram.

So is there any API to add/insert global Tagged Value Types from my Add-Ins.

Thanks

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #4 on: September 06, 2015, 12:43:56 am »
You mean the Default Tagged Values from the Tagged Values window?

q.

dangel

  • EA User
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #5 on: September 06, 2015, 12:59:30 am »
yes  :)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #6 on: September 06, 2015, 03:29:54 am »
There is no API. You need to put them into t_propertytypes via Repositroy.Execute

q.
« Last Edit: September 14, 2015, 02:40:53 pm by qwerty »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #7 on: September 14, 2015, 09:22:09 am »
Try the Repository.PropertyTypes collection.

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #8 on: September 14, 2015, 10:11:09 pm »
The code that Geert gave is proper one.

Here you have a method that I wrote for adding TaggedValues to the element:
Code: [Select]
private bool addTaggedValue(EA.Element req, string tagName)
        {
            TaggedValue tag = req.TaggedValues.GetByName(tagName);
            if (tag == null)
            {
                const string defaultValue = "";
                var element = req.TaggedValues.AddNew(tagName, defaultValue);
                element.Update(); //must be executed in order to save new tagged value
                req.Update(); // is it needed?
                return true;
            }
            return false;
        }

the AddNew method comes from Collection API (link nr 4).

I also recommend those help files for you to uderstand what is going on:
1. http://www.sparxsystems.com/enterprise_architect_user_guide/12/automation_and_scripting/element.html
2. http://www.sparxsystems.com/enterprise_architect_user_guide/12/automation_and_scripting/element2.html
3. http://www.sparxsystems.com/enterprise_architect_user_guide/12/automation_and_scripting/taggedvalue.html
4. http://www.sparxsystems.com/enterprise_architect_user_guide/12/automation_and_scripting/collection.html
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Tomek S

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: How can I INSERT / UPDATE a tag value using EA
« Reply #9 on: October 01, 2015, 11:16:55 pm »
I had the same problem to solve and Simon solution is the only correct for this question.
Thanks Simon!

Quote
Try the Repository.PropertyTypes collection.