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

8 months 2 weeks ago - 8 months 2 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.

8 months 2 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.

1 month 2 weeks ago - 1 month 2 weeks ago #6042 by geraldwarp
This error happens because there is no attribute with the name you called, for that Object. This means that you got the error when the "module" does not contain the method you are calling. But it is evident that the method is there, which leads to believe that may be the method was added by you in the python source code after you had already imported the file (module). Or, some times packages get deprecated and they rename some functions. If that is true, then you may want to exit and reimport the module once again to be able to access the new method.

You can do it in another way to reimport the module with changes without having to exit the interpreter is to do the following:

import importlib
importlib.reload(myModule)

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

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