Book a Demo

Author Topic: Repository.GetCurrentDiagram() returning wrong diagram  (Read 2969 times)

Barrie Treloar

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Repository.GetCurrentDiagram() returning wrong diagram
« on: March 31, 2026, 05:29:38 pm »
In Sparx 15.2

I have two diagrams open, Diagram A and Diagram B.

I run my VBScript from the Specialize > Script Library > Scripts > "my script" > Right click > Run Script

My VBScript calls

Code: [Select]
    dim currentDiagram as EA.Diagram
    set currentDiagram = Repository.GetCurrentDiagram()

When I printout
Code: [Select]
   "currentDiagram = " & currentDiagram.Name
it shows the wrong diagram name "Diagram B".

In
Browser > Project, Diagram A is selected
Browser > Context, Diagram A is selected
Browser > Diagram, Diagram A is selected
Main Window > Diagram A is selected

In the Main Window it is listed as "Diagram A", "Diagram B".

If I swap the order of the diagrams to be "Diagram B", "Diagram A" it prints out the correct name.
If I swap the order of the diagrams to be "Diagram A", "Diagram B" it prints out the incorrect name.

It seems to always select the rightmost diagram.

Am I doing something wrong?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13505
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Repository.GetCurrentDiagram() returning wrong diagram
« Reply #1 on: March 31, 2026, 08:26:03 pm »
Current diagram looks at which diagram is open in the main window.

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8104
  • Karma: +118/-20
    • View Profile
Re: Repository.GetCurrentDiagram() returning wrong diagram
« Reply #2 on: April 02, 2026, 08:01:51 am »
I believe Geert has cut to the core of the issue.

The Browser is not relevant for this function at all.

It gets more complicated than that though:
  • It is possible to drag a tab from the main window out and dock it elsewhere. In that case it becomes the last of the visible main window views that you interacted with.
  • There may not be an active diagram at all. In particular if you're running from a script editor or console, that will be the active window so the current diagram will be null.