Book a Demo

Author Topic: Adding attributes via script  (Read 4506 times)

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Adding attributes via script
« on: March 24, 2015, 07:14:47 am »
So, I am trying to create a script that adds attributes auto-magically to my elements.
The catch is that these attributes are actually stereotypes whose base class is Attribute. Additionally, some of these attribute stereotypes also have tagged values associated with them.

If I was creating elements using script, I would do something like this:

Set repositoryElement = targetPackage.Elements.AddNew(elementName, baseClass)
repositoryElement.PackageID = targetPackage.PackageID
repositoryElement.SynchTaggedValues( profileName, stereotype)
repositoryElement.Update()

As we all know, the element would now be pre-populated with all the tagged values specified in the profile.

BUT....how do I achieve the same thing with attributes?
That is, how do I add all the tagged values that are specified in my attribute stereotype?

Hope this all makes sense.
Thanks in advance

Jays :)


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Adding attributes via script
« Reply #1 on: March 24, 2015, 08:58:29 am »
I think that setting StereotypeEx on the attribute will add the tagged values.

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Re: Adding attributes via script
« Reply #2 on: March 24, 2015, 12:01:02 pm »
Hi Simon

If I understand you correctly, if I do something like this:

Attribute.StereotypeEx = "name of attribute stereotype"

That this will have the same effect as calling SynchronizeTaggedValues on an element.

So, presumably I don't need to specify the profile name as I do with elements because the attribute will assume the same profile as the element it belongs to?

Thanks in advance

Jays :-)

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Re: Adding attributes via script
« Reply #3 on: March 24, 2015, 12:21:12 pm »
Scratch that Simon, just tried it and it works like a charm thus far :-)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Adding attributes via script
« Reply #4 on: March 24, 2015, 02:49:05 pm »
I think StereotypeEx supports setting with a qualified stereotype name. If you don't I expect that it's not as smart as your presumption, just picking the first it finds.