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
' 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