Exemple #1
0
        private void copyShapesNormal()
        {
            //<Snippet14>
            this.Application.Documents.Add("");
            Visio.Page  copyPage;
            Visio.Page  pastePage;
            Visio.Shape rectangle = null;
            Visio.Shape oval      = null;

            Visio.Pages visioPages = this.Application.ActiveDocument.Pages;

            visioPages.Add();

            try
            {
                copyPage  = visioPages[1];
                rectangle = copyPage.DrawRectangle(1.1, 2.2, 4.5, 6.7);
                oval      = copyPage.DrawOval(1, 8.75, 3.5, 6.25);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

            try
            {
                pastePage = visioPages[2];
                rectangle.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
                pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
                oval.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
                pastePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            //</Snippet14>
        }
        private void _GoTo(IVisio.Pages pages, PageDirection flags)
        {
            this._client.Application.AssertApplicationAvailable();

            if (pages == null)
            {
                throw new System.ArgumentNullException(nameof(pages));
            }

            var app             = pages.Application;
            var active_document = app.ActiveDocument;

            if (pages.Document != active_document)
            {
                throw new VisioAutomation.Exceptions.VisioOperationException("Page.Document is not application's ActiveDocument");
            }

            if (pages.Count < 2)
            {
                throw new VisioAutomation.Exceptions.VisioOperationException("Only 1 page available. Navigation not possible.");
            }

            var activepage = app.ActivePage;

            int       cur_index = activepage.Index;
            const int min_index = 1;
            int       max_index = pages.Count;
            int       new_index = PageCommands.move_in_range(cur_index, min_index, max_index, flags);

            if (cur_index != new_index)
            {
                var doc_pages = active_document.Pages;
                var page      = doc_pages[new_index];

                var active_window = app.ActiveWindow;
                active_window.Page = page;
            }
        }
Exemple #3
0
        public static void AutomateVisio()
        {
            Visio.Application oVisio     = null;
            Visio.Documents   oDocs      = null;
            Visio.Document    oDoc       = null;
            Visio.Pages       oPages     = null;
            Visio.Page        oPage      = null;
            Visio.Shape       oRectShape = null;
            Visio.Shape       oOvalShape = null;

            try
            {
                // Create an instance of Microsoft Visio and make it invisible.

                oVisio         = new Visio.Application();
                oVisio.Visible = false;
                Console.WriteLine("Visio.Application is started");

                // Create a new Document based on no template.

                oDocs = oVisio.Documents;
                oDoc  = oDocs.Add("");
                Console.WriteLine("A new document is created");

                // Draw a rectangle and a oval on the first page.

                Console.WriteLine("Draw a rectangle and a oval");

                oPages     = oDoc.Pages;
                oPage      = oPages[1];
                oRectShape = oPage.DrawRectangle(0.5, 10.25, 6.25, 7.375);
                oOvalShape = oPage.DrawOval(1.125, 6, 6.875, 2.125);

                // Save the document as a vsd file and close it.

                Console.WriteLine("Save and close the document");
                string fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample1.vsd";
                oDoc.SaveAs(fileName);
                oDoc.Close();

                // Quit the Visio application.

                Console.WriteLine("Quit the Visio application");
                oVisio.Quit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution1.AutomateVisio throws the error: {0}",
                                  ex.Message);
            }
            finally
            {
                // Clean up the unmanaged Visio COM resources by explicitly
                // calling Marshal.FinalReleaseComObject on all accessor objects.
                // See http://support.microsoft.com/kb/317109.

                if (oOvalShape != null)
                {
                    Marshal.FinalReleaseComObject(oOvalShape);
                    oOvalShape = null;
                }
                if (oRectShape != null)
                {
                    Marshal.FinalReleaseComObject(oRectShape);
                    oRectShape = null;
                }
                if (oPage != null)
                {
                    Marshal.FinalReleaseComObject(oPage);
                    oPage = null;
                }
                if (oPages != null)
                {
                    Marshal.FinalReleaseComObject(oPages);
                    oPages = null;
                }
                if (oDoc != null)
                {
                    Marshal.FinalReleaseComObject(oDoc);
                    oDoc = null;
                }
                if (oDocs != null)
                {
                    Marshal.FinalReleaseComObject(oDocs);
                    oDocs = null;
                }
                if (oVisio != null)
                {
                    Marshal.FinalReleaseComObject(oVisio);
                    oVisio = null;
                }
            }
        }
Exemple #4
0
 public InteractiveRenderer(IVisio.Document doc)
 {
     this._visio_pages = doc.Pages;
     this.Blocks       = new List <TextBlock>();
 }
Exemple #5
0
 public static List <IVisio.Page> ToList(this IVisio.Pages pages)
 {
     return(VisioAutomation.Internal.Extensions.ExtensionHelpers.ToList(() => pages.Count, i => pages[i + 1]));
 }
Exemple #6
0
 public static IEnumerable <IVisio.Page> ToEnumerable(this IVisio.Pages pages)
 {
     return(VisioAutomation.Internal.Extensions.ExtensionHelpers.ToEnumerable(() => pages.Count, i => pages[i + 1]));
 }
 public InteractiveRenderer(IVisio.Document doc)
 {
     this.VisioPages = doc.Pages;
     this.Blocks = new List<TextBlock>();
 }
Exemple #8
0
 public static string[] GetNamesU(this IVisio.Pages pages)
 {
     return(VA.Pages.PageHelper.GetNamesU(pages));
 }
Exemple #9
0
 public static IEnumerable <IVisio.Page> ToEnumerable(this IVisio.Pages pages)
 {
     return(VA.Pages.PageHelper.ToEnumerable(pages));
 }
Exemple #10
0
 /// <summary>
 /// Retrieves a Drawing Page matching the given name.
 /// </summary>
 /// <param name="name">Name of page to retrieve.</param>
 /// <returns>Drawing Page matching name.</returns>
 public static Visio.Page getDrawingPage(Visio.Application app, string name)
 {
     Visio.Pages pages = getPages(app, Visio.VisDocumentTypes.visTypeDrawing);
     return(getPage(pages, name));
 }
 public static List <IVisio.Page> ToList(this IVisio.Pages pages)
 {
     return(ExtensionHelpers.ToList(() => pages.Count, i => pages[i + 1]));
 }
 public static IEnumerable <IVisio.Page> ToEnumerable(this IVisio.Pages pages)
 {
     return(ExtensionHelpers.ToEnumerable(() => pages.Count, i => pages[i + 1]));
 }