Update shape properties


VSTO lets you program with Microsoft Visio files. To update shape properties:

1.Create a Visio application object.
2.Make the application object invisible.
3.Open an existing Visio VSD file.
4.Find the required shape.
5.Update the shape properties (text, text style, position and size).
6.Save the file as VDX.

 Visio.Application vsdApp = null;
            Visio.Document vsdDoc = null;
                //Create Visio Application Object
                vsdApp = Application;

                //Make Visio Application Invisible
                vsdApp.Visible = false;

                //Create a document object and load a diagram
                vsdDoc = vsdApp.Documents.Open( "Drawing.vsd");

                //Create page object to get required page
                Visio.Page page = vsdApp.ActivePage;

                //Create shape object to get required shape
                Visio.Shape shape = page.Shapes["Process1"];

                //Set shape text and text style
                shape.Text = "Hello World";
                shape.TextStyle = "CustomStyle1";

                //Set shape's position
                shape.get_Cells("PinX").ResultIU = 5;
                shape.get_Cells("PinY").ResultIU = 5;

                //Set shape's height and width
                shape.get_Cells("Height").ResultIU = 2;
                shape.get_Cells("Width").ResultIU = 3;

                //Save file as VDX
            catch (Exception ex)
                //Close active document and quit


When programming with Aspose.Diagram, you do not need Microsoft Visio on the machine, and you can work independently of Microsoft Office Automation. To update shape properties with Aspose.Diagram for .NET:

1. Open an existing Visio VSD file.
2. Find the required shape.
3. Update the shape properties (text, text style, position and size).
4. Save the file as VDX.

 //Save the uploaded file as PDF
                Diagram diagram = new Diagram("Drawing1.vsd");

                //Find a particular shape and update its properties
                foreach (Aspose.Diagram.Shape shape in diagram.Pages[0].Shapes)
                    if (shape.Name.ToLower() == "process1")
                        shape.Text.Value.Add(new Txt("Hello World"));

                        //Find custom style sheet and set as shape's text style
                        foreach (StyleSheet styleSheet in diagram.StyleSheets)
                            if (styleSheet.Name == "CustomStyle1")
                                shape.TextStyle = styleSheet;

                        //Set horizontal and vertical position of the shape
                        shape.XForm.PinX.Value = 5;
                        shape.XForm.PinY.Value = 5;

                        //Set height and width of the shape
                        shape.XForm.Height.Value = 2;
                        shape.XForm.Width.Value = 3;

                //Save shape as VDX
                diagram.Save("Drawing1.vdx", SaveFileFormat.VDX);
            catch (Exception ex)


Last edited Jan 1, 2014 at 6:30 AM by asposemarketplace, version 2