コード例 #1
0
        public static void Run()
        {
            // ExStart:GroupShapes
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Load a Visio diagram
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
            // Get page by name
            Page page = diagram.Pages.GetPage("Page-3");

            // Initialize an array of shapes
            Aspose.Diagram.Shape[] ss = new Aspose.Diagram.Shape[3];

            // Extract and assign shapes to the array
            ss[0] = page.Shapes.GetShape(15);
            ss[1] = page.Shapes.GetShape(16);
            ss[2] = page.Shapes.GetShape(17);

            // Mark array shapes as group
            page.Shapes.Group(ss);

            // Save visio diagram
            diagram.Save(dataDir + "GroupShapes_out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:GroupShapes
        }
コード例 #2
0
        public static void Run()
        {
            // ExStart:GroupShapes
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Load a Visio diagram
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
            // Get page by name
            Page page = diagram.Pages.GetPage("Page-3");

            // Initialize an array of shapes
            Aspose.Diagram.Shape[] ss = new Aspose.Diagram.Shape[3];

            // Extract and assign shapes to the array
            ss[0] = page.Shapes.GetShape(15);
            ss[1] = page.Shapes.GetShape(16);
            ss[2] = page.Shapes.GetShape(17);

            // Mark array shapes as group
            page.Shapes.Group(ss);

            // Save visio diagram
            diagram.Save(dataDir + "GroupShapes_Out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:GroupShapes
        }
コード例 #3
0
        public static void Run()
        {
            // ExStart:SettingCellsInEventSection
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_EventSection();

            // Load diagram
            Diagram diagram = new Diagram(dataDir + "TestTemplate.vsdm");

            // Get page
            Aspose.Diagram.Page page = diagram.Pages.GetPage(0);
            // Get shape id
            long shapeId = page.AddShape(3.0, 3.0, 0.36, 0.36, "Square");

            // Get shape
            Aspose.Diagram.Shape shape = page.Shapes.GetShape(shapeId);

            // Set event cells in the ShapeSheet
            shape.Event.EventXFMod.Ufe.F     = "CALLTHIS(\"ThisDocument.ShowAlert\")";
            shape.Event.EventDblClick.Ufe.F  = "CALLTHIS(\"ThisDocument.ShowAlert\")";
            shape.Event.EventDrop.Ufe.F      = "CALLTHIS(\"ThisDocument.ShowAlert\")";
            shape.Event.EventMultiDrop.Ufe.F = "CALLTHIS(\"ThisDocument.ShowAlert\")";
            shape.Event.TheText.Ufe.F        = "CALLTHIS(\"ThisDocument.ShowAlert\")";
            shape.Event.TheData.Ufe.F        = "CALLTHIS(\"ThisDocument.ShowAlert\")";

            // Save diagram
            diagram.Save(dataDir + "SettingCellsInEventSection_out_.vsdm", SaveFileFormat.VSDM);
            // ExEnd:SettingCellsInEventSection
        }
コード例 #4
0
        public static void Run()
        {
            // ExStart:ManipulateObjects
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OLEObjects();

            // Load a Visio diagram
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

            // Get page of the Visio diagram by name
            Aspose.Diagram.Page page = diagram.Pages.GetPage("Page-1");
            // Get shape of the Visio diagram by ID
            Aspose.Diagram.Shape OLE_Shape = page.Shapes.GetShape(1);

            // Filter shapes by type Foreign
            if (OLE_Shape.Type == Aspose.Diagram.TypeValue.Foreign)
            {
                if (OLE_Shape.ForeignData.ForeignType == ForeignType.Object)
                {
                    Stream Ole_stream = new MemoryStream(OLE_Shape.ForeignData.ObjectData);
                    // Get format of the OLE file object
                    Aspose.Words.FileFormatInfo info = Aspose.Words.FileFormatUtil.DetectFileFormat(Ole_stream);
                    if (info.LoadFormat == Aspose.Words.LoadFormat.Doc || info.LoadFormat == Aspose.Words.LoadFormat.Docx)
                    {
                        // Modify an OLE object
                        var doc = new Aspose.Words.Document(new MemoryStream(OLE_Shape.ForeignData.ObjectData));
                        doc.Range.Replace("testing", "Aspose", new Words.Replacing.FindReplaceOptions()
                        {
                            FindWholeWordsOnly = false, MatchCase = true
                        });
                        MemoryStream outStream = new MemoryStream();
                        doc.Save(outStream, Aspose.Words.SaveFormat.Docx);
                        // Save back an OLE object
                        OLE_Shape.ForeignData.ObjectData = outStream.ToArray();
                    }
                }
            }
            // Save Visio diagram
            diagram.Save(dataDir + "ManipulateObjects_out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:ManipulateObjects
        }
コード例 #5
0
        public static void Run()
        {
            // ExStart:SetLineData
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Load a Visio diagram
            Diagram diagram = new Diagram(dataDir + "SetLineData.vsd");

            // Get the page by its name
            Aspose.Diagram.Page page1 = diagram.Pages.GetPage("Page-1");
            // Get shape by its ID
            Aspose.Diagram.Shape shape = page1.Shapes.GetShape(1);
            // Set line dash type by index
            shape.Line.LinePattern.Value = 4;
            // Set line weight, defualt in PT
            shape.Line.LineWeight.Value = 2;
            // Set color of the shape's line
            shape.Line.LineColor.Ufe.F = "RGB(95,108,53)";
            // Set line rounding, default in inch
            shape.Line.Rounding.Value = 0.3125;
            // Set line caps
            shape.Line.LineCap.Value = BOOL.True;
            // Set line color transparency in percent
            shape.Line.LineColorTrans.Value = 50;

            /* add arrows to the connector or curve shapes */
            // Select arrow type by index
            shape.Line.BeginArrow.Value = 4;
            shape.Line.EndArrow.Value   = 4;
            // Set arrow size
            shape.Line.BeginArrowSize.Value = ArrowSizeValue.Large;
            shape.Line.BeginArrowSize.Value = ArrowSizeValue.Large;

            // Save the Visio
            diagram.Save(dataDir + "SetLineData_out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:SetLineData
        }
コード例 #6
0
        private static void GetShapeText(Aspose.Diagram.Shape shape)
        {
            // Filter shape text
            if (shape.Text.Value.Text != "")
            {
                text += Regex.Replace(shape.Text.Value.Text, "\\<.*?>", "");
            }

            // For image shapes
            if (shape.Type == TypeValue.Foreign)
            {
                text += (shape.Name);
            }

            // For group shapes
            if (shape.Type == TypeValue.Group)
            {
                foreach (Aspose.Diagram.Shape subshape in shape.Shapes)
                {
                    GetShapeText(subshape);
                }
            }
        }
コード例 #7
0
        public static void Run()
        {
            // ExStart:FormatShapeTextBlockSection
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ShapeTextBoxData();

            // Load source Visio diagram
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

            // Get the page by its name
            Aspose.Diagram.Page page1 = diagram.Pages.GetPage("Page-1");
            // Get shape by its ID
            Aspose.Diagram.Shape shape = page1.Shapes.GetShape(1);
            // Set orientation angle
            DoubleValue margin = new DoubleValue(4, MeasureConst.PT);

            // Set left, right, top and bottom margins of the shape's text block
            shape.TextBlock.LeftMargin   = margin;
            shape.TextBlock.RightMargin  = margin;
            shape.TextBlock.TopMargin    = margin;
            shape.TextBlock.BottomMargin = margin;
            // Set the text direction
            shape.TextBlock.TextDirection.Value = TextDirectionValue.Vertical;
            // Set the text alignment
            shape.TextBlock.VerticalAlign.Value = VerticalAlignValue.Middle;
            // Set the text block background color
            shape.TextBlock.TextBkgnd.Ufe.F = "RGB(95,108,53)";
            // Set the background color transparency in percent
            shape.TextBlock.TextBkgndTrans.Value = 50;
            // Set the distance between default tab stops for the selected shape.
            shape.TextBlock.DefaultTabStop.Value = 2;

            // Save Visio
            diagram.Save(dataDir + "FormatShapeTextBlockSection_Out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:FormatShapeTextBlockSection
        }
        public static void Run()
        {
            //ExStart:SaveVisioShapeInOtherFormats
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // call a Diagram class constructor to load the VSDX diagram
            Diagram srcVisio = new Diagram(dataDir + "Drawing1.vsdx");

            double shapeWidth  = 0;
            double shapeHeight = 0;

            // get Visio page
            Aspose.Diagram.Page srcPage = srcVisio.Pages.GetPage("Page-3");
            // remove background page
            srcPage.BackPage = null;

            // get hash table of shapes, it holds id and name
            Hashtable remShapes = new Hashtable();

            //Hashtable<Long, String> remShapes = new Hashtable<Long, String>();
            foreach (Aspose.Diagram.Shape shape in srcPage.Shapes)
            {
                // for the normal shape
                remShapes.Add(shape.ID, shape.Name);
            }

            // iterate through the hash table
            foreach (DictionaryEntry shapeEntry in remShapes)
            {
                long   key = (long)shapeEntry.Key;
                string val = (string)shapeEntry.Value;
                Aspose.Diagram.Shape shape = srcPage.Shapes.GetShape(key);
                // check of the shape name
                if (val.Equals("GroupShape1"))
                {
                    // move shape to the origin corner
                    shapeWidth  = shape.XForm.Width.Value;
                    shapeHeight = shape.XForm.Height.Value;
                    shape.MoveTo(shapeWidth * 0.5, shapeHeight * 0.5);
                    // trim page size
                    srcPage.PageSheet.PageProps.PageWidth.Value  = shapeWidth;
                    srcPage.PageSheet.PageProps.PageHeight.Value = shapeHeight;
                }
                else
                {
                    // remove shape from the Visio page and hash table
                    srcPage.Shapes.Remove(shape);
                }
            }
            remShapes.Clear();

            // specify saving options
            Aspose.Diagram.Saving.PdfSaveOptions opts = new Aspose.Diagram.Saving.PdfSaveOptions();
            // set page count to save
            opts.PageCount = 1;
            // set starting index of the page
            opts.PageIndex = 1;
            // save it
            srcVisio.Save(dataDir + "SaveVisioShapeInOtherFormats_Out.pdf", opts);
            //ExEnd:SaveVisioShapeInOtherFormats
        }