Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Barrie Treloar on March 31, 2026, 05:29:38 pm

Title: Repository.GetCurrentDiagram() returning wrong diagram
Post by: Barrie Treloar 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?
Title: Re: Repository.GetCurrentDiagram() returning wrong diagram
Post by: Geert Bellekens on March 31, 2026, 08:26:03 pm
Current diagram looks at which diagram is open in the main window.

Geert
Title: Re: Repository.GetCurrentDiagram() returning wrong diagram
Post by: Eve 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: