Skip to main content

Edit the shape display order

Bring a shape to the front​

To bring a shape to the front, use the BringToFront method of the IShape object.

public void BringToFront(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram.
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null)
{
//If no diagram is displayed, exit.
return;
}

//Get the node shape selected on the diagram.
INode node = diagram.GetSelectedShapes().OfType<INode>().FirstOrDefault();
if (node ​​== null)
{
//If no node shape is selected, exit.
return;
}

//Bring the shape to the front.
node.BringToFront();
}
info

If you want to bring a shape one step forward from the current display, use the BringForward method of the IShape object.

Send a shape to the back​

To send a shape to the back, use the SendToBack method of the IShape object.

public void SendToBack(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null)
{
//If no diagram is displayed, terminate the process
return;
}

//Get the node shape selected on the diagram.
INode node = diagram.GetSelectedShapes().OfType<INode>().FirstOrDefault();
if (node ​​== null)
{
//If no node shape is selected, end processing
return;
}

//Send the shape to the back
node.SendToBack();
}
info

If you want to send a shape one layer back from the current display, use the SendBackward method of the IShape object.

Set the shape display order (Z order) directly​

The SetZOrder method of the IShape object allows you to directly set the display order (Z order) with a numerical value. This can be used when importing diagram information from an external tool.

public void SetZOrder(ICommandContext c, ICommandParams p)
{
//Get node shapes from the currently displayed diagram by specifying conditions.
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null)
{
//End processing if no diagram is displayed.
return;
}
List<INode> nodes = diagram.Nodes.ToList();
//Import diagram information from an external tool and sort node shapes from the results.
nodes.Sort(...);

int zOrder = 0;
foreach (INode node in nodes)
{
//Set the display order (Z order) of node shapes directly with a number.
node.SetZOrder(zOrder);
zOrder++;
}
}
info
  • No error occurs even if the display order of a shape is set to the same Z order as other shapes.
  • If there are multiple shapes with the same Z order, the display order of those shapes is undefined.

Get the display order (Z order) of a shape​

To get the display order (Z order) of a shape, use the ZOrder property of the IShape object.

public void GetZOrder(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null)
{
//If no diagram is displayed, terminate the process
return;
}

//Get the node shape selected on the diagram.
INode node = diagram.GetSelectedShapes().OfType<INode>().FirstOrDefault();
if (node ​​== null)
{
//If no node shape is selected, end processing
return;
}

//Get the display order (Z order) of the node shape
c.App.Output.WriteLine("sample", $"Shape display order (Z order): {node.ZOrder}");
}