Author Topic: How to capture a Sparx EA event in a Python program  (Read 2371 times)

pvickers

  • EA User
  • **
  • Posts: 44
  • Karma: +7/-0
    • View Profile
How to capture a Sparx EA event in a Python program
« on: February 05, 2020, 05:26:31 am »
I would like to be able to call a python program from Sparx EA, and have this program receive various events.

For example, when the user selects a different view, package, element etc. in EA's browser I want to capture those events in my python program.

I have done this before using vbscript and javascript, but would like to be able to do this with python.

I've reviewed the Sparx documentation regarding add-in development (in C# for example) but I'm hoping someone can provide guidance on how this can be done using python.

Thanks,
Perry


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to capture a Sparx EA event in a Python program
« Reply #1 on: February 05, 2020, 05:51:53 am »
You would need to write a wrapper (e.g. in C#) to do that. You can't register Python programs with Windoze since they are interpreted, rather than compiled. I once tried various Pythton "compilers". They all were scrap.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13226
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to capture a Sparx EA event in a Python program
« Reply #2 on: February 05, 2020, 08:34:42 am »
I made a add-in (EA-Matic) that does this for internal scripts.
It "subscribes" to all EA events, and forwards them to the scripts.

I guess you could fairly easy extend that code to call python scripts instead.

You can find the code for it here: https://github.com/GeertBellekens/Enterprise-Architect-Toolpack/tree/master/EAScriptAddin

Geert

pvickers

  • EA User
  • **
  • Posts: 44
  • Karma: +7/-0
    • View Profile
Re: How to capture a Sparx EA event in a Python program
« Reply #3 on: February 05, 2020, 09:23:19 am »
Thanks Qwerty and Geert,

Very helpful information.

I prefer not to have to write a special wrapper for this so I will test using the EA-Matic add-in.

Regards,
Perry

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to capture a Sparx EA event in a Python program
« Reply #4 on: February 05, 2020, 09:50:34 am »
Actually I wrote a wrapper in C# for Python (for a customer). It was fairly easy and is very versatile as I can configure with a yaml (or whatever) where to look for Python scripts and how they shall appear in EA's menu. I haven't used the broadcasts yet, but the hooks are there and they can be configured a similar way.

q.

pvickers

  • EA User
  • **
  • Posts: 44
  • Karma: +7/-0
    • View Profile
Re: How to capture a Sparx EA event in a Python program
« Reply #5 on: February 06, 2020, 09:12:05 am »
The wrapper approach or using the EA-Matic add-in are great options that I will certainly keep in mind in the future.
However for the problem at hand, I have decided to proceed with developing a stand-alone (python) program with an independent UI.

Perry