file AttributeError: '...ActivityDiagra' object has no attribute 'getOwnedNode'

1 month 3 weeks ago - 1 month 3 weeks ago #5824 by nicol
I'm using a script to find all paths in an Activity Diagram. To do it, I use Modelio 4.0.

I put the below script in a macro.

Script
## return first initial node in the selected activity
def getInitialPoint(act):
    for node in act.getOwnedNode():
        if isinstance(node, InitialNode):
            return node

## parcours activity nodes
def getPaths(currentPath, currentNode): 
    for outgoing in currentNode.getOutgoing():
        node = outgoing.getTarget()
        if isinstance(node, ActivityFinalNode):
            paths.append(currentPath)
            return;
        elif  isinstance(node, DecisionMergeNode):
            getPaths(currentPath, node)  
        else:           
            getPaths(currentPath + " - "  + node.getName(), node) 

 ##Init
init = getInitialPoint(elt)
currentPath = init.getName()
global paths
paths = []
getPaths(currentPath, init)

 ##Print founded paths
for p in paths:
    print p

Error

But when I launch the macro, I'm facing the below error:
AttributeError: 'org.modelio.metamodel.impl.diagrams.ActivityDiagra' object has no attribute 'getOwnedNode' in <script> at line number 20
Traceback (most recent call last):
File "<script>", line 20, in <module>
File "<script>", line 3, in getInitialPoint
AttributeError: 'org.modelio.metamodel.impl.diagrams.ActivityDiagra' object has no attribute 'getOwnedNode'

Could you please help me to fix it please? Thank you.

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

1 month 3 weeks ago #5825 by ebr
Hi Nicol,

Please find below a updated version of your script which will work if you launch it from an Activity or an Activity Diagram element. I have to say that this script will work in all cases (if you have a sub activity for example).

Hoping it helps,
EBR aka RedBeard
## return first initial node in the selected activity
def getInitialPoint(act):
  for  node in act.getOwnedNode():
    if isinstance(node, InitialNode):
      return node

## parcours activity nodes
def getPaths(currentPath, currentNode): 
  for outgoing in currentNode.getOutgoing():
    node = outgoing.getTarget()
    if isinstance(node, ActivityFinalNode):
      paths.append(currentPath)
      return;
    elif  isinstance(node, DecisionMergeNode):
      getPaths(currentPath, node)  
    else:           
      getPaths(currentPath + " - "  + node.getName(), node) 

## main function
def main(act):
  init = getInitialPoint(act)
  currentPath = init.getName()
  global paths
  paths = []
  getPaths(currentPath, init)

  ##Print founded paths
  for p in paths:
    print p 
    
##Init
if isinstance(elt, Activity):
  main(elt)
elif isinstance(elt, ActivityDiagram):
  if isinstance(elt.getOrigin(), Activity):
    main(elt.getOrigin())
else:
  print "Wrong seletected element"

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

Moderators: tmachmaab
Time to create page: 0.036 seconds
^ Back to Top