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
        }
Exemple #2
0
        public static void Run()
        {
            // ExStart:AddLayer
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Layers();

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

            // Get Visio page
            Aspose.Diagram.Page page = diagram.Pages.GetPage("Page-1");

            // Initialize a new Layer class object
            Layer layer = new Layer();

            // Set Layer name
            layer.Name.Value = "Layer1";
            // Set Layer Visibility
            layer.Visible.Value = BOOL.True;
            // Set the color checkbox of Layer
            layer.IsColorChecked = BOOL.True;
            // Add Layer to the particular page sheet
            page.PageSheet.Layers.Add(layer);

            // Get shape by ID
            Shape shape = page.Shapes.GetShape(3);

            // Assign shape to this new Layer
            shape.LayerMem.LayerMember.Value = layer.IX.ToString();
            // Save diagram
            diagram.Save(dataDir + "AddLayer_Out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:AddLayer
        }
Exemple #3
0
        public static void Run()
        {
            //ExStart:RefreshMilestoneWithMilestoneHelper
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            string pageName = @"Page-1";

            ////////////// Modify time line ///////////
            DateTime startDate = new DateTime(2015, 8, 1);

            DateTime endDate = new DateTime(2016, 6, 1);

            DateTime fisYear = startDate;

            //Load a diagram
            Diagram diagram = new Diagram(dataDir + "input.vdx");

            //Get page
            Aspose.Diagram.Page page = diagram.Pages.GetPage(pageName);

            long timelineId = 1;

            Shape timeline = diagram.Pages.GetPage(pageName).Shapes.GetShape(timelineId);

            double xpos = timeline.XForm.PinX.Value;

            double ypos = timeline.XForm.PinY.Value;

            // Add milestone
            string milestoneMasterName = "2 triangle milestone";

            //Add Master
            diagram.AddMaster(dataDir + "Timeline.vss", milestoneMasterName);

            //Add Shape in Visio diagram using AddShape method
            long milestoneShapeId = diagram.AddShape(xpos, ypos, milestoneMasterName, 0);

            //Get the shape based on ID
            Shape milestone = page.Shapes.GetShape(milestoneShapeId);

            //Instantiate MilestoneHelper object
            MilestoneHelper milestoneHelper = new MilestoneHelper(milestone);

            //Set Milestone Date
            milestoneHelper.MilestoneDate = new DateTime(2015, 8, 1);

            //Set IsAutoUpdate to true
            milestoneHelper.IsAutoUpdate = true;

            //RefreshMilesone of timeline shape
            milestoneHelper.RefreshMilestone(timeline);

            //Save Visio file
            diagram.Save(dataDir + "output.vdx", SaveFileFormat.VDX);
            //ExEnd:RefreshMilestoneWithMilestoneHelper
        }
Exemple #4
0
        public static void Run()
        {
            // ExStart:CopyVisioPage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_VisioPages();

            // Initialize the new visio diagram
            Diagram NewDigram = new Diagram();

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

            // Add all masters from the source Visio diagram
            foreach (Master master in dgm.Masters)
            {
                NewDigram.Masters.Add(master);
            }

            // Get page object
            Aspose.Diagram.Page SrcPage = dgm.Pages.GetPage("Page-1");
            // Set name
            SrcPage.Name = "new page";

            // It calculates max page id
            int max = 0;

            if (NewDigram.Pages.Count != 0)
            {
                max = NewDigram.Pages[0].ID;
            }

            for (int i = 1; i < NewDigram.Pages.Count; i++)
            {
                if (max < NewDigram.Pages[i].ID)
                {
                    max = NewDigram.Pages[i].ID;
                }
            }

            // Set max page ID
            int MaxPageId = max;

            // Set page ID
            SrcPage.ID = MaxPageId + 1;

            // Add page from the source diagram
            NewDigram.Pages.Add(SrcPage);
            // Remove first empty page
            NewDigram.Pages.Remove(NewDigram.Pages[0]);
            // Save diagram
            NewDigram.Save(dataDir + "CopyVisioPage_Out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:CopyVisioPage
        }
        public static void Run()
        {
            // ExStart:SetVisioPageOrientation
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_VisioPages();

            // Initialize the new visio diagram
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

            // Get Visio page
            Aspose.Diagram.Page page = diagram.Pages.GetPage("Flow 1");
            // Page orientation
            page.PageSheet.PrintProps.PrintPageOrientation.Value = PrintPageOrientationValue.Landscape;
            // Save Visio
            diagram.Save(dataDir + "SetPageOrientation_out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:SetVisioPageOrientation
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ShapeText();
            // Load diagram
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

            // Get Visio diagram page
            Aspose.Diagram.Page page = diagram.Pages.GetPage("Page-1");

            // Iterate through the shapes
            foreach (Aspose.Diagram.Shape shape in page.Shapes)
            {
                // Extract plain text from the shape
                GetShapeText(shape);
            }
            // Display extracted text
            Console.WriteLine(text);
        }
        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
        }
Exemple #8
0
        public static void Run()
        {
            //ExStart:RetrieveAllLayers
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Layers();

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

            // get Visio page
            Aspose.Diagram.Page page = diagram.Pages.GetPage("Page-1");

            // iterate through the layers
            foreach (Layer layer in page.PageSheet.Layers)
            {
                Console.WriteLine("Name: " + layer.Name.Value);
                Console.WriteLine("Visibility: " + layer.Visible.Value);
                Console.WriteLine("Status: " + layer.Status.Value);
            }
            //ExEnd:RetrieveAllLayers
        }
        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
        }
Exemple #10
0
        public static void Run()
        {
            // ExStart:CopyShape
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

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

            // Initialize a new Visio
            Diagram newDiagram = new Diagram();

            // Add all masters from the source Visio diagram
            MasterCollection originalMasters = srcVisio.Masters;

            foreach (Master master in originalMasters)
            {
                newDiagram.AddMaster(srcVisio, master.Name);
            }

            // Get the page object from the original diagram
            Aspose.Diagram.Page SrcPage = srcVisio.Pages.GetPage("Page-1");
            // Copy themes from the source diagram
            newDiagram.CopyTheme(srcVisio);
            // Copy pagesheet of the source Visio page
            newDiagram.Pages[0].PageSheet.Copy(SrcPage.PageSheet);

            // Copy shapes from the source Visio page
            foreach (Aspose.Diagram.Shape shape in SrcPage.Shapes)
            {
                newDiagram.Pages[0].Shapes.Add(shape);
            }
            // Save the new Visio
            newDiagram.Save(dataDir + "CopyShapes_Out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:CopyShape
        }
        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
        }