Book a Demo

Author Topic: Attribute type namespace=?  (Read 3690 times)

PAF

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Attribute type namespace=?
« on: January 13, 2022, 03:28:09 am »
Friends, thanks in advance for your time!

Please suggest a better way to learn the namespace of Type of Attribute of Class?

So far I could dig it up like this and this does not feel elegant/effective:

Code: [Select]
var p = Repository.GetTreeSelectedPackage()
  var e = p.Elements.GetByName("Usage")
  var a2 = e.Attributes.GetAt(13);
 
    for (var i = 0; i < a2.TypeInfoProperties.Count; i++) {
        var prop = a2.TypeInfoProperties.Items(i);
    Session.Output(prop.Name+": "+prop.Value);
    // name: exampleProductUsage
    // type: {F903116B-4D2B-48e8-884B-9B8392F1C7DB}
    }
    // could not find a way to get property by name instead of scanning all items
    // TypeInfoProperties.GetProperty("name") returns empty string for me (15.2.1555)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Attribute type namespace=?
« Reply #1 on: January 13, 2022, 05:14:46 am »
What exactly do you mean by the namespace of the attribute type?

If you mean the first EA package (going upwards from the type element) that has "isNamespace" poperty set, you would have to do something like this

- get the type element using Attribute.ClassifierID as parameter for Repository.GetElementByID
- get the package owning the type element using Element.PackageID as parameter for Repository.GetPackageByID
- check the property Package.IsNamespace to know if this package is a namespace
- recurse upwards through the package tree using package.ParentID untill you find one that is a namespace (or untill you hit the root package)

Geert

PAF

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Attribute type namespace=?
« Reply #2 on: January 13, 2022, 05:32:09 am »
dear Geert, thanks a ton, this ClassifierID magic allows to do things faster and cleaner, and is exactly what I was after. Docs are kinda misleading here, I feel

Quote
The ElementID of a Classifier associated with this element; that is, the base type. Only valid for instance type elements (such as Object or Sequence).

I thought I don't need *base* type, and I was working with Class, not an Object or Sequence.
But it worked just fine.

About namespace=true/false, I'm a newbie and didn't give that much thought yet. In my green head they are all the same as of now. But I see relevant property and would read upon that.

Recusion on finding good parent idea is clear. Thanks again.
Alexander

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Attribute type namespace=?
« Reply #3 on: January 13, 2022, 06:30:07 am »
Alexander,

It helps if you read the right documenation.

In this case we are talking about the ClassifierID of EA.Attribute, not the ClassifierID of EA.Element.
https://sparxsystems.com/enterprise_architect_user_guide/15.2/automation/attribute.html
If you look here it says:

Quote
The classifier ID, if appropriate, indicating the base type associated with the attribute, if not a primitive type.


This property will have value 0 (zero) if there is no type element selected, but instead the type was typed in or chosen from the dropdown.
In that case you only have Attribute.Type

Geert