check [Solved] get value of taggedValue

1 year 11 months ago - 1 year 11 months ago #5331 by Ralf Ebert
Hi,

I've defined a stereotype a, which contains a tag named b. I have added this stereotype to a package and set the value of the property b to c.

Now I tried to get the value in a script using
for stereotype in package.getExtension():
  name=stereotype.getName();
  if (name == "a"):
    for tagType in s.getDefinedTagType():
      if tagType.getName() == "b":
        taggedValue = tagType.getTagOccurence()
        if None != taggedValue:
          value = taggedValue.getActual().getValue()

but I get the error
AttributeError: 'org.modelio.vcore.smkernel.SmList' object has no attribute 'getActual' in <script> at line number 100

If I use the
taggedValue = tagType.getTagOccurence(TaggedValue)
I get the same result ...

Can anyone tell me, what I make wrong?

Best regards
Ralf Ebert

Please Log in or Create an account to join the conversation.

1 year 11 months ago - 1 year 11 months ago #5334 by ebr
Hi Ralf,

According to the metamodel documentationn , both "TagOccurence" and "Actual" relationships return a List of, respectively, "TaggedValue" and "TagParameter" elements.
So you have to go through all the element returned by these relationships.

One other point is by using the "TagOccurrence" relationship, your code manipulates all TaggedVallue which have "b" as Definition and not only the one owned by your selected element...

Maybe the following code will help you.

It starts from the selected element "elt" and get all TaggedValue owned by it.
Then the code checks the name of the TaggedVallue and of its Definition and if they are respectively equals to "b" and "a", it gets the "Actual" list of TagParameter, takes the first one and return its value.
for t in elt.getTag():
  tagType = t.getDefinition();
  if (tagType.getName() == "b") and (tagType.getOwnerStereotype().getName() == "a"):
  	print t.getActual().get(0).getValue()

Cheers,
EBR

Please Log in or Create an account to join the conversation.

1 year 11 months ago #5335 by Ralf Ebert
Hi ebr,

thank you for your code example, it works fine for me. It seems I've misunderstood the metamodel documentation ...

Best regards
Ralf Ebert

Please Log in or Create an account to join the conversation.

Moderators: tma
Time to create page: 0.035 seconds
^ Back to Top