Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: zpeter on August 06, 2009, 08:06:20 pm

Title: animation state diagram
Post by: zpeter on August 06, 2009, 08:06:20 pm
Hi everyone,
is in EA any possibility of animation the state diagram?

Thanks
Title: Re: animation state diagram
Post by: dmf on August 14, 2009, 02:56:26 pm
I'd say automation is your best bet.  I've considered this myself.
Title: Re: animation state diagram
Post by: fginfrance on October 03, 2009, 08:20:55 am
Hi,

below a code snippet.
Sorry, it is in Python and from what I have seen in the forum, this is not really mainstream, but the COM32 wrapper is thin, so you should be able to port easily.

For the example, you need to have a StateMachine Diagram "smDiag" in your Model:
- open EA, your model and the Diagram "smDiag"
- start the script
--> script will find "smDiag" and start cycling through the states with an interval of 2 sec

It's quite rudimentary, but shows the way to go. The tough part was to find the right refresh commands, but this forum really helped...

Have fun!
fginfrance

Code: [Select]
#!/usr/bin/python
# -*- coding: UTF-8 -*-

# $Id: smAnim $

import sys
import os
import win32com.client
import time

def playSM( eaTheRep, eaPack ):

  print eaPack.Name
  
  for eaDiag in eaPack.Diagrams:
      if eaDiag.Name == "smDiag":

        for elem in range( 0 , 25 ):
          idx = 0
          for obj in eaDiag.DiagramObjects:

            if (idx == elem % 5):
              obj.Style = "BCol=22220000;BFol=0;LCol=0;LWth=2;"
            else:
              obj.Style = "BCol=88880000;BFol=0;LCol=0;LWth=1;"
            idx += 1        
            obj.Update()

          eaTheRep.FlagUpdate = True
          eaTheRep.ReloadDiagram( eaDiag.DiagramID )
          time.sleep( 2 )

def connect(  ):
  """ Connect to Word COM server """

  eaApp = win32com.client.Dispatch("EA.App")  
  eaRep = eaApp.Repository
  print "connecting...", eaRep.ConnectionString

  print "DONE"
  return eaRep

if __name__ == '__main__':

  eaRepo = connect()

  for eaModel in eaRepo.Models:
    for eaPkg in eaModel.Packages:
      playSM( eaRepo, eaPkg )