We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Shape with ID '' does not present on the page

When I set the ID of a shape and then add it to a diagram, why does the shape's ID change to some sort of auto-incremented ID (1,2,3,4,5...)?

How am I supposed to connect a shape by ID if it's ID is being automatically changed to a sequential number once it is added to a diagram?



Diagram diagram = new Diagram(visioStencil);
Shape shape = new Shape();
shape.ID = 5;
shape.Name = String.Format("Rectangle {0}", 5);
shape.Text.Value.Add(new Txt("Hello"));
shape.SetWidth(width);
shape.SetHeight(height);
shape.Line.LineColor.Value = "7";
shape.Line.LineWeight.Value = 0.03;
shape.XForm.PinX.Value = pinX;
shape.XForm.PinY.Value = pinY;
diagram.AddShape(shape, rectangleMaster, pageNumber);


-----------


foreach (Shape s in diagram.Pages[0].Shapes)
{
System.Windows.Forms.MessageBox.Show(string.Format("ID: {0}\nName: {1}\nText: {2}\nUniqueID: {3}",s.ID, s.Name, s.Text, s.UniqueID));
}


-----------------
ID: 1
Name: Rectangle 5
Text: Aspose.Diagram.Text
UniqueID: 00000000-0000-0000-0000-000000000000
---------------------------

Hi Brian,

AddShape method returns the ID of the newly added shape so you can use that ID to update a shape. Once a shape is added, you can change its ID if you want to assign a specific ID to a shape but in this case, you will have to make sure that new ID is not already assigned to any other shape (i.e. IDs should be unique).

Please check add and connect shapes example for more details and feel free to contact us in case you have further comments or questions.

Best Regards,

I have gotten it to work by setting the value I want as the ID to be the shape’s name, and then after they are added to the diagram, I loop through all shapes and set the ID to the Name and that restores the ID’s I wanted. They are all unique because they are from a SQL Database Identity Field.

Hi Brain,


Thank you for writing to us about this way around. It is nice to hear from you that the problem has been solved. Please feel free to reply us if you have any question regarding Aspose.BarCode API, we will be happy to help you.