Category / Section
How can I progammatically add a symbol from the palette?
2 mins read
How can I progammatically add a symbol from the palette?
The following code sample demonstrates how you can progamatically add a symbol from the symbol palette to a Diagram.
[C#]
//New InsertNodesCmd InsertNodesCmd insCmd = new InsertNodesCmd(); //Select the Symbol from the PaletteGroupView this.paletteGroupView1.SelectSymbolModel(this.paletteGroupView1.GroupViewItems[1].Text); SymbolModel symModel = this.paletteGroupView1.SelectedSymbolModel; //New NodeCollection NodeCollection nodes = new NodeCollection(); //Add Symbol to the NodeCollection if (symModel != null) { Symbol triangle = symModel.CreateSymbol(); nodes.Add(triangle); } insCmd.Nodes.Concat(nodes); insCmd.Location = new PointF(125,125); //ExecuteCommand to add the Symbol this.diagram1.Controller.ExecuteCommand(insCmd);
[VB.NET]
'New InsertNodesCmd Dim insCmd As New InsertNodesCmd() 'Select the Triangle from the PaletteGroupView Me.paletteGroupView1.SelectSymbolModel(Me.paletteGroupView1.GroupViewItems(1).Text) Dim symModel As SymbolModel = Me.paletteGroupView1.SelectedSymbolModel 'new NodeCollection Dim nodes As New NodeCollection() 'Add Symbol to the NodeCollection If Not (symModel Is Nothing) Then Dim triangle As Symbol = symModel.CreateSymbol() nodes.Add(triangle) End If insCmd.Nodes.Concat(nodes) insCmd.Location = New PointF(125, 125) 'Execute the InsertNodesCmd Me.diagram1.Controller.ExecuteCommand(insCmd)