Hi Geert,
I've found a solution that works for my scenario. Maybe it's useful for someone else so I wanted to share it here.
The main idea is to use EA's shortcuts.
Scenario 1:
The element - that is not a connector - has just an instance on one diagram.
Solution:
Select the element in the project browser via
repository.ShowInProjectView(element).
After that send the shortcut
Ctrl-U for
Find in all diagrams... to EA. That way the diagram opens and the element appears almost centered and selected in the view.
Scenario 2:
The element - that is not a connector - has several instances on more diagrams.
Solution:
Select the element in the project browser via
repository.ShowInProjectView(element).
After that send the shortcut
Ctrl-U for
Find in all diagrams... to EA. That way a dialog pops up where the user can select which diagram he wants to open.
Scenario 3:
a) The element is a connnector.
b) The element has several instances on more diagrams but you want to directly open a special diagram without the selection dialog popping up.
Solution:
Open the diagram, select the element/connector and send a shortcut for
Zoom in. The
Zoom in does not only zoom into the view but also centers the selected item. But to be able to call the
Zoom in the shortcut must be defined previously in
Tools\Customize....
Here are some extension methods as code snippets to give you more than just the explanations above. If somebody wants to use this approach the
Windows Input Simulator is required. Please have look here
https://archive.codeplex.com/?p=inputsimulator.
/// <summary>
/// Select element in project browser.
/// </summary>
/// <param name="repository">The EA repository.</param>
/// <param name="elementId">The ID of the <see cref="EA.Element"/>.</param>
public static void SelectElementInProjectBrowser(this EA.Repository repository, int elementId)
{
// Select element in project browser.
EA.Element element = repository.GetElementByID(elementId);
repository.ShowInProjectView(element);
}
/// <summary>
/// Sends the shortcut "Ctrl+U" to the EA window and executes the command "Find in all diagrams...".
/// </summary>
/// <param name="repository">The EA repository.</param>
public static void CallFindSelectedItemOfProjectBrowserInAllDiagramsViaKeystroke(this EA.Repository repository)
{
// Open diagram and unselect all elements.
var diagram = repository.GetCurrentDiagram();
if (diagram != null)
{
UnselectAllElementsOf(diagram);
}
var sim = new InputSimulator();
Application.DoEvents();
EaWindow.Activate();
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_U);
}
/// <summary>
/// Sends the shortcuts "Ctrl + +" and "Ctrl + -" to the EA window and executes the commands
/// "Zoom in" and "Zoom out". That way the selected items appear centered in the diagram.
/// </summary>
private static void CallZoomInAndZoomOutViaKeystrokes()
{
var sim = new InputSimulator();
Application.DoEvents();
EaWindow.Activate();
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.OEM_PLUS);
Application.DoEvents();
EaWindow.Activate();
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.OEM_MINUS);
}
To complete the solution above it would be great to be able to define shortcuts via the addin. But that will be the subject of another topic...

Sven