Book a Demo

Author Topic: API EA.Diagram Method to get the Focus/reference selected object  (Read 1798 times)

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1410
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Hi,
With a diagram script I can control and access the selected objects with diagram.SelectedObjects.
I'd like to get the focus/reference object e.g. if you select several classes, unselect and reselect one, it is shown with a hatched border. It doesn't seem to be possible to find this object in the script. Could a method be provided to do so ?
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8112
  • Karma: +119/-20
    • View Profile
Re: API EA.Diagram Method to get the Focus/reference selected object
« Reply #1 on: July 13, 2026, 09:37:39 am »
Repository.GetContextItem() and Repository.GetContextObject() both give you the object that has its properties displayed. That could be the object you've asked for but it could also be the browser selection.

If you want to be more precise use

Repository.CurrentSelection

It was designed to address the limitation that we offer Diagram.SelectedObjects and the Repository functions mentioned above but no way to get multiple selection in other places. That's important because it gives you enough information to know if the focused element in on a diagram.

If I had your need with EA "as is", I would use something like this:

Code: [Select]
function FocusedElement {
    if( Repository.CurrentSelection.Location == "Diagram")
        return Repository.GetContextObject();
    else
        return null;
}

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1410
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: API EA.Diagram Method to get the Focus/reference selected object
« Reply #2 on: July 17, 2026, 04:53:27 pm »
Hi Eve,

Thank you for the advice. I confirm that Repository.GetContextObject(); returns the "reference" element from the diagram.

Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com