0

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.

Royce
  • 1,557
  • 5
  • 19
  • 44
  • What is `elt` ? Where is defined? – Hackerman Feb 12 '20 at 14:50
  • It is a value provided by modelio. This message is displayed in the console :`The following variables are bound: - session : the opened session (IModelingSession ) - elt : the first selected model element or null (Element) - elements : the selected model elements (Collection) - selection : the SWT selection (ISelection) Use 'session.getModel().getModelRoots()' to get the roots of each work fragment.` – Royce Feb 12 '20 at 14:56

1 Answers1

1

In fact, elt is the selected Element. This script works if you launch it from an Activity Element and not a Activity Diagram.

Best,

Red Beard
  • 3,436
  • 1
  • 14
  • 17