Author Topic: How to detect an already open diagram  (Read 4996 times)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8605
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
How to detect an already open diagram
« on: June 17, 2010, 02:27:05 am »
It's been a long day and I can't find any method for detecting if a diagram that I want to get from the repository (say via GetDiagramByGuid()) is already open in the Workspace.

Can someone tell me if it's possible and if so how?

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

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: How to detect an already open diagram
« Reply #1 on: June 17, 2010, 03:03:26 am »
Paolo,
The only resources that I'm aware of would be to use the EA_OnPostOpenDiagram and EA_OnPostCloseDiagram methods to detect when diagrams are opened and closed. Then you'd have a list of open diagrams that could be compared to the diagram you are trying to get. Of course this assumes that you are using an add-in.

Jim

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8605
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to detect an already open diagram
« Reply #2 on: June 17, 2010, 09:34:42 am »
Hi Jim,

That late in the day I was hoping to avoid the broadcast events and have a more direct route.

Oh well...

I'll pop a feature request in (after I get the code working...)

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

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: How to detect an already open diagram
« Reply #3 on: June 17, 2010, 02:27:00 pm »
Hi Paolo,

The only other suggestion I can think of at the moment is Repository.IsTabOpen(TabName).  This only allows you to query the open tabs by name though, so might not tell you if the exact diagram you are asking for is open, just that there is one with the same name.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8605
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to detect an already open diagram
« Reply #4 on: June 17, 2010, 02:30:57 pm »
Thanks Aaron,

I'd already considered that but it's not selective enough as you point out.

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

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8078
  • Karma: +118/-20
    • View Profile
Re: How to detect an already open diagram
« Reply #5 on: June 18, 2010, 08:27:12 am »
Okay, I'll got one step further with an option that may work but is a bit ugly.

Code: [Select]
CurrentID = Repository.GetCurrentDiagram().DiagramID
Repository.ActivateDiagram(DiagramID)
if(Repository.GetCurrentDiagram().DiagramID == DiagramID)
{
  IsOpen = True
}
Repository.ActivateDiagram(CurrentID)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8605
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to detect an already open diagram
« Reply #6 on: June 18, 2010, 10:15:04 am »
Hi Simon,

So I'm clear...

You're saying if I try to activate the desired diagram and it works, then it was open in the first place.  I wasn't sure if activate wouldn't open the diagram if it was closed.

Thanks,
Paolo
« Last Edit: June 18, 2010, 06:57:01 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8078
  • Karma: +118/-20
    • View Profile
Re: How to detect an already open diagram
« Reply #7 on: June 21, 2010, 08:35:25 am »
The documentation suggests that it should work.

Quote
ActivateDiagram (long DiagramID)
  
 Activates an already open diagram (that is, makes it the active tab) in the main Enterprise Architect user interface.

as opposed to

Quote
OpenDiagram (long DiagramID)
  
 Provides a method for an automation client or Add-In to open a diagram. The diagram is added to the tabbed list of open diagrams in the main Enterprise Architect view.

Parameters:

DiagramID: Long - the ID of the diagram to open.  
« Last Edit: June 21, 2010, 08:36:22 am by simonm »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8605
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to detect an already open diagram
« Reply #8 on: November 24, 2010, 02:04:44 pm »
Quote
The documentation suggests that it should work.
[size=18]...[/size]
As Maxwell Smart would say: "Missed it by that much!"

Although ActivateDiagram doesn't open a closed diagram, it gives you NO indication of the state of the diagram after the execution of the method.

See: ActivateDiagram should return result

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