Get selected shapes
To get the shapes selected in a diagram, use the GetSelectedShapes
method of the IDiagram
object.
public void GetSelectedNodes(ICommandContext c, ICommandParams p)
{
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null) return;
//Get the selected nodes
var nodes = diagram.GetSelectedShapes().OfType<INode>();
//Process each node
foreach (INode node in nodes)
{
c.App.Output.WriteLine("sample", $"Node model : {node.Model.Name}");
}
}
Get the selected port
The selected port can be obtained by casting to the IPort
type when the shape is obtained using the GetSelectedShapes
method of the IDiagram
object.
public void GetSelectedPorts(ICommandContext c, ICommandParams p)
{
var diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null) return;
//Get the selected ports
var ports = diagram.GetSelectedShapes().OfType<IPort>();
c.App.Output.WriteLine("sample",$"Number of selected ports: {ports.Count()}");
}