Book a Demo

Author Topic: Get ClassifierID  and PropertyType of element  (Read 7070 times)

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Get ClassifierID  and PropertyType of element
« on: August 19, 2013, 08:57:40 pm »
Hi,

I have a script where I would like to get access to the namespace of an element. I have a faint memory of this not being possible throught the API? But I guess it would be possible through an sql query?  But where is this information hidden?

E.g. How is it possible to know that MyNode is a MyNodeType?

<<Node>> MyNode : MyNodeType

Thank you in advance!


Edit: Changed the subject name since later posts show it was not Namespace I was looking for.
« Last Edit: August 19, 2013, 10:44:30 pm by Sorno »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Get Fully Qualified Namespace of element
« Reply #1 on: August 19, 2013, 09:16:10 pm »
Right out of memory: you need to go up the parent list of the element until you reach one with the flag namespace root and then reverse join the package names. There was a thread where Geert posted a code snippet. (Good luck when searching)

q.
« Last Edit: August 19, 2013, 09:17:14 pm by qwerty »

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Get Fully Qualified Namespace of element
« Reply #2 on: August 19, 2013, 09:44:52 pm »
Thanks for the input! Alas, I can't find the post you refered to. I think I have read all post by Geert, aswell as all post mentioning "namespace" or "type" with no luck.

I wonder if I have mixed up the names of things. Is it even called namespace what I'm trying to get at?

To clarify:
I have an element (MyNode) that is an instance of another element (MyNodeType). In the project browser it looks like I posted above: <<Node>>MyNode :MyNodeType.

In the properties window of the element I can see the value (MyNodeType) in the "Type"-field under the Property tab. But my script returns only "Part" when I ask for MyNode.Type.
 
« Last Edit: August 19, 2013, 09:47:23 pm by Sorno »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Get Fully Qualified Namespace of element
« Reply #3 on: August 19, 2013, 10:07:24 pm »
I think you're asking two different questions.

The fully-qualified namespace is not stored in any table. It is not available in the API, nor by a (simple) SQL query because its depth is arbitrary.
You can retrieve the element's package (Element.PackageID / t_object.Package_ID), and from the package you can get its parent (Package.ParentID / t_package.Parent_ID), and so on until you hit the namespace root (Package.IsNamespace / t_package.Namespace) or the package root node (Package.IsModel / t_package.Parent_ID = 0).

Note that, depending on your metamodel, if the element is located inside another element that should or should not be reflected in the namespace. If so, you need to start not with the element's containing package but with its containing element: Element.ParentID / t_object.ParentID; 0 if the element has no parent (which is where you start traversing up the package tree).

Thus far namespaces. What you're describing with MyNode : MyNodeType is the instance / classifier relationship. You find the classifier of an instance in Element.ClassifierID or t_object.Classifier. Note that Element.Type is simply the UML type of the element, ie Class, Component, Object, Part, etc.

To get the fully-qualified classifier name of an instance you'd have to first retrieve the classifier, then construct its namespace as outlined above.
« Last Edit: August 19, 2013, 10:08:20 pm by Uffe »
My theories are always correct, just apply them to the right reality.

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Get Fully Qualified Namespace of element
« Reply #4 on: August 19, 2013, 10:22:51 pm »
Ahh! Thank you Uffe for sorting out my mess.

You are absolutely correct that I have mixed things up. It is the ClassifierID I'm after.

But I have a strange thing in my model:

<<Node>> MyNode :MyNodeType
<<OperationalSwimLane>> MyNode: MyNodeType

Note the placement of the colon ( : ). In traceability in both cases it mention a "Instance of" relationship. ClassifierID works on the second case, but not the first. In the first case the ClassifierID returns 0. Something is amiss?

 Any ideas?


« Last Edit: August 19, 2013, 10:23:57 pm by Sorno »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Get Fully Qualified Namespace of element
« Reply #5 on: August 19, 2013, 10:36:16 pm »
In the case of a Property (the artist formerly known as Part) or Port, there is no classifier but a property type, which is similar.

Look at Element.PropertyType or t_object.PDATA1, and note that while PropertyType is an integer matching the property type's ElementID, PDATA1 is a string element matching its ElementGUID.

Ports and Properties / Parts are commonly used in Component and Deployment models.
My theories are always correct, just apply them to the right reality.

Sorno

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Get Fully Qualified Namespace of element
« Reply #6 on: August 19, 2013, 10:42:00 pm »

Thank you both so much for the help!

Case closed. ;)