Book a Demo

Author Topic: Weird stereotype behaviour - quick answer appreciated a lot!  (Read 7969 times)

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
(EA12.1 W7 64 bit)

An Activity created from the BPMN2.0 palette has these stereotype values (dumped by script)

Type: Activity
Stereotype: Activity
StereotypeEX: Activity
FQStereotype: BPMN2.0::Activity
   
How can I get this combination by setting values with a script? Please try it - I'd love to know that it can be done in practice!

General issue: StereotypeEx is not supposed** to return the fully qualified stereotype, but it does, so after setting stereotype "BPMN2.0::Activity" I get this

Stereotype: BPMN2.0::Activity
StereotypeEX: BPMN2.0::Activity
FQStereotype: BPMN2.0::Activity

the best I can manage - and only by setting "Activity" in various places - gives me

Stereotype: Activity
StereotypeEX: Activity
FQStereotype: BPMN::Activity

and BPMN::Activity (obviously) doesn't have the right tagged values

Really struggling... and it's Friday and the task should be done today :(

Thanks, Julian

** can't find the equivalent 12.1 page but the 13.0 help page for this is http://sparxsystems.com/enterprise_architect_user_guide/13.0/automation/element2.html.

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: Weird stereotype behaviour - quick answer appreciated a lot!
« Reply #1 on: June 23, 2017, 10:43:11 pm »
Hi,

In my VBscript I just use:

Set activity = package.Elements.AddNew (activityName, "BPMN2.0::Activity")
activityName.Update

And the activity has the correct BPMN2.0 tagged values.

Regards,

Jon.

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: Weird stereotype behaviour - quick answer appreciated a lot!
« Reply #2 on: June 23, 2017, 11:17:57 pm »
Hi Jon

I think I've done that successfully myself - the issue is converting an Action to an Activity because of a) data already in the Action elements b) the layout - size, position, connectors and their routing, etc. etc.

The scrappy dev code is below for info...

Best regards

Julian

Code: [Select]
' Loosely based on Geert Belleken's "synchronize"
sub OnDiagramScript()
' one or all of these is required to get the property pane to show the new properties inc. TV on type change, but it does do it ... I think
'callingElement.Refresh
'Repository.AdviseElementChange(callingElement.ElementID)
'currentDiagram.Update


dim currentDiagram as EA.Diagram
dim diagObj as EA.DiagramObject
dim anEl as EA.Element
dim scriptDataStr
dim params
dim elStereo
dim elReferencedEntity
dim classifierID
dim t
dim aColl as EA.Collection
dim i
dim anotherEl as EA.Element
dim calledElement as EA.Element
dim callingElement as EA.Element
dim calledActivityRefTV as EA.TaggedValue
dim isACalledActivityTV as EA.TaggedValue
dim calledActivityDiagram as EA.Diagram
dim calledElementTV as EA.TaggedValue

Repository.EnsureOutputVisible "Script"

set currentDiagram = Repository.GetCurrentDiagram() ' Get a reference to the current diagram
' set currentDiagram = Repository.GetDiagramByGuid("{3E337347-30A8-4a1f-B763-433F2EF53943}") ' N - Notified Aid in the ISIS part of Library test

Session.output ("Developer wrapper")
if not currentDiagram is nothing then
if currentDiagram.selectedObjects.Count = 1 then ' For test purposes - faster, less risk
set diagObj = currentDiagram.selectedObjects(0) ' index base 0
set anEl = Repository.GetElementByID(diagObj.ElementID)
if anEl.Type = "Action" then
set callingElement = anEl
set calledElement = getInstanceCallBehaviourElement(callingElement)

Session.output ("callingElement.name = " & callingElement.name & " calls " & calledElement.name)

' change the source element type from Action to Activity
callingElement.Type = "Activity"
callingElement.Stereotype = "BPMN2.0::Activity" ' fully qualified otherwise no TVs created
callingElement.Update ' must update element before TV refresh
callingElement.TaggedValues.Refresh

' point the Activity at the called element
set calledActivityRefTV = callingElement.TaggedValues.GetByName("calledActivityRef")
if not calledActivityRefTV is nothing then
calledActivityRefTV.Value = calledElement.ElementGUID
calledActivityRefTV.Update
callingElement.ClassifierID = 0 ' now the ref has been transferred, clear the ClassifierID
callingElement.Update
else
Session.output "Calling activity doesn't have a tagged value calledActivityRef!"
end if

' Tell the calling element it is called
set isACalledActivityTV = calledElement.TaggedValues.GetByName("isACalledActivity")
if isACalledActivityTV is nothing then
set isACalledActivityTV = calledElement.TaggedValues.AddNew("isACalledActivity","TaggedValue")
end if
if not isACalledActivityTV is nothing then
isACalledActivityTV.Value = True
isACalledActivityTV.Update
calledElement.Update
else
Session.output "Could not create tagged value isACalledActivity!"
end if

' Associate the diagram - doesn't work!!
set calledActivityDiagram = getCalledElementDiagram(calledElement)
if not calledActivityDiagram is nothing then
setCompositeDiagram callingElement, calledActivityDiagram
' check
if callingElement.Diagrams.Count = 0 then
Session.output("calledActivityDiagram set failed")
else
set calledActivityDiagram = callingElement.Diagrams(0)
Session.output("calledActivityDiagram.Name = " & calledActivityDiagram.Name)
end if
else
Session.output("Called activity doesn't have a diagram")
end if

' change all appropriate links

end if
else
Session.output ("One at a time")
end if

else
Session.Prompt "This script requires a diagram to be visible", promptOK
end if
Session.output ("End sub")
end sub

function getInstanceCallBehaviourElement(anEl)
' if course anEL must be of an instance type, e.g. Action, Object, Sequence - don't have a list so will see what happens when I get it for something it doesn't exist for
' Well. band new Activity has a classifier ID of 0 and no type; an activity with a calledActivityRef has the classifier ID of the called activity!
dim baseEl as EA.Element

if anEl.Type = "Action" Or anEl.type = "Object" Or anEl.type = "Sequence" then
if anEl.ClassifierID > 0 then
set getInstanceCallBehaviourElement = Repository.GetElementByID(anEl.ClassfierID)
end if
end if

end function


KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Weird stereotype behaviour - quick answer appreciated a lot!
« Reply #3 on: June 26, 2017, 09:26:06 am »
Try adding an extra Update after setting the type to Activity:

Quote
callingElement.Type = "Activity"
callingElement.Update
callingElement.Stereotype = "BPMN2.0::Activity" ' fully qualified otherwise no TVs created
callingElement.Update

I haven't tried it, but I suspect that otherwise when applying the stereotype EA might still think the element is an Action.
« Last Edit: June 26, 2017, 01:16:28 pm by KP »
The Sparx Team
[email protected]

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Weird stereotype behaviour - quick answer appreciated a lot!
« Reply #4 on: June 26, 2017, 11:28:33 am »
This will break things.
Code: [Select]
element.Stereotype="BPMN2.0::Activity";
For legacy reasons, the property Element.Stereotype does not support fully qualified names. The code above will actually define a new stereotype in the model with the name BPMN2.0::Activity. It is a completely separate stereotype from the Activity stereotype from the BPMN2.0 profile.

You should use:
Code: [Select]
element.StereotypeEx="BPMN2.0::Activity";
This will parse the assigned string, and set the stereotype to the one from the requested profile.
« Last Edit: June 26, 2017, 12:46:05 pm by Simon M »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Weird stereotype behaviour - quick answer appreciated a lot!
« Reply #5 on: June 26, 2017, 01:15:29 pm »
For legacy reasons, the property Element.Stereotype does not support fully qualified names. The code above will actually define a new stereotype in the model with the name BPMN2.0::Activity. It is a completely separate stereotype from the Activity stereotype from the BPMN2.0 profile.

You should use:
Code: [Select]
element.StereotypeEx="BPMN2.0::Activity";
This will parse the assigned string, and set the stereotype to the one from the requested profile.
You should also go ribbon | Configure | UML Types and delete any stereotypes named BPMN2.0::Activity
The Sparx Team
[email protected]

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: Weird stereotype behaviour - quick answer appreciated a lot!
« Reply #6 on: June 26, 2017, 07:41:57 pm »
This will break things.
Code: [Select]
element.Stereotype="BPMN2.0::Activity";
For legacy reasons, the property Element.Stereotype does not support fully qualified names. The code above will actually define a new stereotype in the model with the name BPMN2.0::Activity. It is a completely separate stereotype from the Activity stereotype from the BPMN2.0 profile.

You should use:
Code: [Select]
element.StereotypeEx="BPMN2.0::Activity";
This will parse the assigned string, and set the stereotype to the one from the requested profile.

OK, so that's why StereotypeEx was including the BPMN2.0:: because the whole thing was being treated as a stereotype - got it.

Thanks

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: Weird stereotype behaviour - quick answer appreciated a lot!
« Reply #7 on: June 26, 2017, 07:42:59 pm »
@KP - also thanks for the tip to delete the miscreated stereotypes