Author Topic: GetCurrentDiagram always returns nothing  (Read 21258 times)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8595
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #15 on: March 21, 2017, 10:44:19 am »
Just to be clear, we have already started EA (it may or may not have been in [X] Run as Administrator).  Then we decide to do something that requires our "Helper" in Excel.  By default, this does NOT start in  [X] Run as Administrator mode so if EA is in Administrator,  it cannot find the EA instance.  We don't start EA from the Helper.

Paolo

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

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #16 on: March 21, 2017, 11:57:40 am »
Just to be clear, we have already started EA (it may or may not have been in [X] Run as Administrator).  Then we decide to do something that requires our "Helper" in Excel.  By default, this does NOT start in  [X] Run as Administrator mode so if EA is in Administrator,  it cannot find the EA instance.  We don't start EA from the Helper.

Install sysinternals process monitor (it's free) and see what actually is happening.  From what you're saying it sounds like you're trying to be malware and hijack another process, but I may not be understanding you clearly.  Process monitor should show you what is actually happening, and may even show you if you've ended up with two completely separate security contexts.

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #17 on: September 17, 2017, 07:30:22 am »
I have very similar issue, but when running script from EA Scripting.
I have opened diagram in EA. It is even selected in Project Browser.
While running script listed bellow I got the error "diagram is null"

Code: [Select]
!INC Local Scripts.EAConstants-JScript

function main()
{
var diagram as EA.Diagram;

diagram = Repository.GetCurrentDiagram();
Repository.ReloadDiagram(diagram.DiagramID); /* throws error: diagram is NULL */

}

main();

I can reference diagram using GUID and GetDiagramByGuid() method. Then it works.
What am I doing wrong?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #18 on: September 17, 2017, 06:50:21 pm »
The diagram must be visible. Just selecting it in the browser won't work.

q.

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #19 on: September 17, 2017, 08:00:21 pm »
Didn't I write it's already opened? OK, I wasn't precize enough. It was opened and visible. No other diagrams were opened.
« Last Edit: September 17, 2017, 08:17:09 pm by MaXyM »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #20 on: September 18, 2017, 03:21:39 am »
Was just making sure... Anyhow, this rather looks like an issue with the J(ava)Script itself. Unfortunately I can't help with that.

q.

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #21 on: September 18, 2017, 03:56:17 am »
OK. I'll try VB and let know.
I like more C-like syntax, that's why I used JavaScript.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #22 on: September 18, 2017, 06:31:37 am »
Ah. Stupid me. When I ran the snippet, the script editor was in the focus :-( Running from the scripting tree it showed no issue.

q.
« Last Edit: September 18, 2017, 06:33:51 am by qwerty »

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #23 on: September 18, 2017, 06:28:31 pm »
Nice find.
So it seems to be a bug.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13240
  • Karma: +553/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: GetCurrentDiagram always returns nothing
« Reply #24 on: September 18, 2017, 07:07:57 pm »
Nice find.
So it seems to be a bug.

No, if you have a script in the main window then there is no Current Diagram.

Geert

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #25 on: September 18, 2017, 07:24:41 pm »
Could you elaborate more?
From my understanding, once I open a diagram and let it shown, there is (have to be) current diagram.
What do you mean by 'script in the main window'? Do you mean, once I have opened script, then no diagram can be simultaneously visible?
I can do that by having scripting window floating (usually on second monitor). Then I can see an opened diagram being current.

Side-question: how to debug a script which uses GetCurrentDiagram method? ;)
« Last Edit: September 18, 2017, 08:52:37 pm by MaXyM »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #26 on: September 18, 2017, 08:05:30 pm »
I guess you can't debug that from inside EA. I'm using scripts that run outside EA where it's easily possible to do that.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13240
  • Karma: +553/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: GetCurrentDiagram always returns nothing
« Reply #27 on: September 18, 2017, 09:41:19 pm »
Could you elaborate more?
From my understanding, once I open a diagram and let it shown, there is (have to be) current diagram.
What do you mean by 'script in the main window'? Do you mean, once I have opened script, then no diagram can be simultaneously visible?
I can do that by having scripting window floating (usually on second monitor). Then I can see an opened diagram being current.

Side-question: how to debug a script which uses GetCurrentDiagram method? ;)
What if you have two floating diagram windows? Which one should EA then consider to be the current?
AFAIK GetCurrentDiagram only returns the visible diagram in the main window.
For debugging purposes you can float the script window instead of the diagram window and debug it like that.

Geert

MaXyM

  • EA User
  • **
  • Posts: 120
  • Karma: +8/-0
    • View Profile
Re: GetCurrentDiagram always returns nothing
« Reply #28 on: September 18, 2017, 10:55:33 pm »
Geert, I have written already: I have script window floating which causes described issue.
The diagram is docked to main window.

I have to check running scripts from outside, but I'm not sure it is possible to use JS language in this case.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13240
  • Karma: +553/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: GetCurrentDiagram always returns nothing
« Reply #29 on: September 18, 2017, 11:07:35 pm »
Geert, I have written already: I have script window floating which causes described issue.
The diagram is docked to main window.
Sorry I must have missed that.

Anyway, what I usually do to debug my scripts is to comment out the call to the main function and create a "test" function.
In this test function, instead of getting the current diagram, I test my functionality with a specific diagram which I get based on it's GUID.
That allows me to test 99% of my script code. The only thing that I'm not able to test this way is the GetCurrentDiagram call itself, but I'm sure that works just fine.

Geert