Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: qwerty on May 10, 2012, 10:38:33 pm
-
When you right click any element or connector in a diagram then EA offers the addin-menu in the context. I faintly remember a method to retrieve the selected element(s) in a diagram. But I can't find it now. How can I find out which element(s)/connector is/are selected in the diagram from an add-in?
q.
-
The Diagram class contains a read only collection property SelectedObjects, I guess that's what you're looking for (see http://www.sparxsystems.com/enterprise_architect_user_guide/9.3/automation/diagram2.html).
HTH
Günther
-
Doh! I like EA. GetTreeSelectedObject is in Repository. Of course this one is in Diagram. I was looking for GetDiagramSelectedObject or the like...
Thanks!
q.
-
Interestingly there is also a property SelectedConnector (which I did not expect...). The documentation tells this is r/w. For curiosity sake I tried setting this to zero (thus deselecting the connector). Well, that did not work. I guess this is an error in the documentation and it's meant to be r/o -> Roy?
q.
-
I always use getContextItem:
Here's the code I use for getting and setting the selected element from https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/Model.cs
/// the Element currently selected in EA
public UML.Classes.Kernel.Element selectedElement {
get {
Object selectedItem;
try
{
this.wrappedModel.GetContextItem(out selectedItem);
return this.factory.createElement(selectedItem);
}
catch (COMException)
{
//something went wrong
return null;
}
}
set
{
if (value is Package)
{
this.wrappedModel.ShowInProjectView(((Package)value).wrappedPackage);
}
else if (value is ElementWrapper)
{
this.wrappedModel.ShowInProjectView(((ElementWrapper)value).wrappedElement);
}
else if (value is Operation)
{
this.wrappedModel.ShowInProjectView(((Operation)value).wrappedOperation);
}
else if (value is Attribute)
{
this.wrappedModel.ShowInProjectView(((Attribute)value).wrappedAttribute);
}
else if (value is Parameter)
{
Operation operation = (Operation)((Parameter)value).operation;
this.wrappedModel.ShowInProjectView(operation.wrappedOperation);
}
}
}
But that only returns one object, not a collection.
Geert
-
Truly Konzistend. Multiple elements selected are not in a "real" context. Neither in a diagram nor in the browser.
However, thanks for the note :-) Might be useful, though.
q.