Change the visibility of shapes
Show shapes
To display multiple shapes, use the ShowShapes
method of the IDiagram
object.
public void ShowShapes(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null)
{
//If the diagram is not displayed, exit the process
c.App.Output.WriteLine("sample", "Diagram is not displayed.");
return;
}
//Get the shapes present in the diagram
INodeCollection nodes = diagram.Nodes;
if (!nodes.Any())
{
//If there are no nodes on the diagram, exit the process
c.App.Output.WriteLine("sample", "There are no shapes on the currently displayed diagram.");
return;
}
//Show the shapes hidden on the diagram
c.App.Output.WriteLine("sample", $"Show the shapes corresponding to the following models.");
foreach (INode node in nodes.Where(n => !n.IsVisible))
{
c.App.Output.WriteLine("sample", $" - {node.Model.Name}");
//To show a single shape, use the ShowShape method of IDiagram.
//diagram.ShowShape(node);
}
diagram.ShowShapes(nodes);
}
Hide shapes
To hide multiple shapes, use the HideShapes
method of the IDiagram
object.
public void HideShapes(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
//Get the currently selected shapes
IEnumerable<INode> nodes = diagram.GetSelectedShapes().OfType<INode>();
//Hide shapes on the diagram
c.App.Output.WriteLine("sample", $"Hide shapes corresponding to the following models");
foreach (INode node in nodes)
{
c.App.Output.WriteLine("sample", $" - {node.Model.Name}");
//To hide a single shape, use the HideShape method of IDiagram.
//diagram.HideShape(node);
}
diagram.HideShapes(nodes);
}
Note
You can also change the visibility of a shape using the SetVisible
method of the IShape
object, but if you are changing the visibility of multiple shapes, performance issues may occur. Therefore, consider using the ShowShapes
and HideShapes
methods of the IDiagram
object.