Book a Demo

Author Topic: Debugging a diagram script  (Read 4901 times)

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
Debugging a diagram script
« on: May 29, 2020, 03:58:47 am »
Hi, I am very new to scripting in EA so it is most probably an obvious thing. I already found a lot of answers to things that I did not get working initially but this one I (till now) did not succeed to solve on my own.

I am creating some POC scripts to see what is possible in EA scripting and I started to create a diagram script. However it contains an error (and will contain more in the future) and I wanted to debug it. However if I start the debugger from the script window there is no diagram selected and my script fails. But if I start the script from the diagram window then I cannot start it in debugging mode.
O yes I am using JavaScript but that won't change anything I think.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Debugging a diagram script
« Reply #1 on: May 29, 2020, 05:21:36 am »
Use an IDE from outside EA.

q.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Debugging a diagram script
« Reply #2 on: May 29, 2020, 08:18:16 am »
Hi Arnoud,

We use a "trick".  We have a global variable.  If the value is zero it uses the current diagram else it opens the diagram specified by the variable.  It DOES mean you need to know either the GUID or the ID of the diagram, but...

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Debugging a diagram script
« Reply #3 on: May 29, 2020, 01:34:24 pm »
In those cases I often use a test sub, and comment out the main sub.

So it would be something like

Code: [Select]
sub main
   -- code to get the open diagram
   -- call the function that does the actual work with the diagram as parameter
end sub

'main

sub test
   -- code to get the test diagram based on the guid
   -- call the function that does the actual work with the diagram as parameter
end sub

test

Need to remember to remove the debug code after fixing the problem and before putting the script into production though

Paolo's solution seems smarter

Geert

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
Re: Debugging a diagram script
« Reply #4 on: May 30, 2020, 06:57:49 am »
Thanks for your replies it is really good to have a forum and get responses as the documentation is reasonably good but it is still a niche market with not that many good examples and guidebooks etc. I was already thinking in the direction of Paolo's solution but indeed testing on a NULL value and than setting the value to the test diagram seems a neat solution. My solution was more crude in just have a setter that I commented out.

A question to QUERTY is there any documentation on how to use for instance Eclipse or IntelliJ to SparxEA both as script editor and debugger? I think the internal IDE is pretty OK but it lacks refactoring capabilities and other things I was used to as Java developer (or I just did not find them yet ;-P )

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Debugging a diagram script
« Reply #5 on: May 30, 2020, 07:18:04 am »
Well, I'm using Python with WingPro which works a charme for me - but probably not for you. However, there are lots of people out there using Eclipse and whatever. You just need to use the API provided by Sparx. This internal scripting is a toy. Any IDE outside compared to that can be called a tool.

q.

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
Re: Debugging a diagram script
« Reply #6 on: June 03, 2020, 01:33:45 am »
I agree that the editor is not what I am used to, but for now I'll manage doing my little examples. But when we start real programming so (time) investment in setting up a correct development environment will be won back quickly.