public IVisio.Document Render(IVisio.Application app)
        {
            var docs = app.Documents;
            var doc = docs.Add("");

            var ctx = new FormRenderingContext(app);
            ctx.Application = app;
            ctx.Document = doc;
            ctx.Pages = doc.Pages;
            ctx.Fonts = doc.Fonts;

            this.VisioDocument = doc;

            doc.Subject = this.Subject;
            doc.Title = this.Title;
            doc.Creator = this.Creator;
            doc.Company = this.Company;

            var pages = doc.Pages;
            foreach (var formpage in this.Pages)
            {
                var page = formpage.Draw(ctx);
            }

            if (pages.Count > 0)
            {
                // Delete the empty first page
                var first_page = VisioDocument.Pages[1];
                first_page.Delete(1);
                first_page = pages[1];
                var active_window = app.ActiveWindow;
                active_window.Page = first_page;
            }
            return doc;
        }
Esempio n. 2
0
 /// <summary>
 /// Gets a Master by the masterName.
 /// </summary>
 /// <param name="app">Application in which all Documents resides.</param>
 /// <param name="stencilName">Name of the Stencil in which the Master resides.</param>
 /// <param name="masterName">Name of the Master to get.</param>
 /// <returns></returns>
 public static Visio.Master getMasterFromStencil(Visio.Application app,
                                                 string stencilName, string masterName)
 {
     Visio.Document stencil = getStencil(app.Documents, stencilName,
                                         Visio.VisOpenSaveArgs.visOpenHidden);
     return(stencil.Masters[masterName]);
 }
Esempio n. 3
0
        public void violationValidator(Visio.Shapes shapes, Visio.Document document, Visio.ValidationRuleSet violationValidatorRuleSet)
        {

            foreach(Visio.Shape shape in shapes)
            {
                if(shape.Master.Name == "Violation")
                {
                    var outgoingShapes = new List<Visio.Shape>();
                    Array outgoing1Dshapes = shape.GluedShapes(Visio.VisGluedShapesFlags.visGluedShapesOutgoing1D, "");
                    if(outgoing1Dshapes.Length == 0)
                    {
                        // Issue Handling: Violation Event muss einen ausgehenden DangerFlow haben. (shape weil event markiert werden soll)
                        //customRule2.AddIssue(shape.ContainingPage, shape);
                        violationValidatorRuleSet.Rules.get_ItemFromID(2).AddIssue(shape.ContainingPage, shape);
                        continue;
                    }
                    foreach (Object element in outgoing1Dshapes)
                    {
                        outgoingShapes.Add(shapes.get_ItemFromID((int)element));
                    }
                    foreach(Visio.Shape element in outgoingShapes)
                    {
                        if(element.Master.Name != "DangerFlow")
                        {
                            //Issue Handling: Outgoing Flow ist kein DangerFlow (element weil Flow markiert werden soll)
                            //customRule1.AddIssue(shape.ContainingPage, element);
                            violationValidatorRuleSet.Rules.get_ItemFromID(1).AddIssue(shape.ContainingPage, element);
                        }
                    }
                }              
            }
        }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Create Visio Application Object
            Visio.Application vsdApp = Application;

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

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

            //Save the VDX diagram
            vsdDoc.SaveAs("Drawing1.vdx");

            //Save as PDF file
            vsdDoc.ExportAsFixedFormat(Visio.VisFixedFormatTypes.visFixedFormatPDF,
                                       "Drawing1.pdf", Visio.VisDocExIntent.visDocExIntentScreen,
                                       Visio.VisPrintOutRange.visPrintAll, 1, vsdDoc.Pages.Count, false, true,
                                       true, true, true, System.Reflection.Missing.Value);

            Visio.Page vsdPage = vsdDoc.Pages[1];

            //Save as JPEG Image
            vsdPage.Export("Drawing1.jpg");

            //Quit Visio Object
            vsdApp.Quit();
        }
Esempio n. 5
0
        public static void FontGlyphComparision2(IVisio.Document doc, string[] fontnames, List <string> samplechars)
        {
            double w  = 2.0;
            double h  = 1;
            double th = 1;

            int chunksize = 12;
            var chunks    = LinqUtil.Split(samplechars, chunksize);

            foreach (var chunk in chunks)
            {
                var domshapescol = new VA.DOM.ShapeList();

                for (int j = 0; j < fontnames.Count(); j++)
                {
                    string fontname = fontnames[j];
                    double x0       = j * w;

                    var r  = new VA.Drawing.Rectangle(x0, 0 - th, x0 + w, 0);
                    var n1 = domshapescol.Drop("Rectangle", "basic_u.vss", r);
                    n1.Text = new VA.Text.Markup.TextElement(fontname.ToUpper());
                    n1.Cells.FillForegnd = "rgb(255,255,255)";
                    n1.Cells.LineWeight  = 0.0;
                    n1.Cells.LinePattern = 0;
                    n1.Cells.CharSize    = "16pt";
                }


                for (int j = 0; j < fontnames.Count(); j++)
                {
                    for (int i = 0; i < chunksize; i++)
                    {
                        double x0 = j * w;
                        double y0 = i * h * -1 - th - h;

                        var r  = new VA.Drawing.Rectangle(x0, y0, x0 + w, y0 + h);
                        var n1 = domshapescol.Drop("Rectangle", "basic_u.vss", r);
                        if (i < chunk.Count)
                        {
                            n1.Text = new VA.Text.Markup.TextElement(chunk[i]);
                        }
                        else
                        {
                            // empty
                        }
                        n1.CharFontName      = fontnames[j];
                        n1.Cells.CharSize    = "36pt";
                        n1.Cells.FillForegnd = "rgb(255,255,255)";
                        n1.Cells.LineWeight  = 0.0;
                        n1.Cells.LinePattern = 0;
                    }
                }

                var page = doc.Pages.Add();
                domshapescol.Render(page);

                var bordersize = new VA.Drawing.Size(0.5, 0.5);
                page.ResizeToFitContents(bordersize);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Connects a fromShape to a toShape using a Dynamic Connector.
        /// </summary>
        /// <param name="page">Page to drop the Shapes in.</param>
        /// <param name="fromShape">The Shape to start the connection at.</param>
        /// <param name="toShape">The Shape to end the connection at.</param>
        /// <param name="fromXPercent">
        /// X coordinate (in percent of the fromShape's width) to Glue</param>
        /// <param name="fromYPercent">
        /// Y coordinate (in percent of the fromShape's height) to Glue.</param>
        /// <param name="toXPercent">
        /// X coordinate (in percent of the toShape's width) to Glue.</param>
        /// <param name="toYPercent">
        /// X coordinate (in percent of the toShape's width) to Glue.</param>
        public static void glueShapesWithDynamicConnector(Visio.Page page, Visio.Shape fromShape, Visio.Shape toShape,
                                                          double fromXPercent, double fromYPercent, double toXPercent, double toYPercent)
        {
            Visio.Documents appDocuments = page.Application.Documents;

            // We only want to get the Dynamic Connector Master from the Stencil,
            // so keep the stencil hidden since user won't need to use it.
            Visio.Document stencil = getStencil(appDocuments, CaseTypes.OOSD_GENERAL_STENCIL,
                                                Visio.VisOpenSaveArgs.visOpenHidden);

            Visio.Master connectorMaster = stencil.Masters[CaseTypes.OOSD_CONNECTOR];
            Visio.Shape  connector       = page.Drop(connectorMaster, 0, 0);

            // The Dynamic Connector has an end point and a begin point, which are
            // the glue points used to connect to shapes. These points are stored
            // in the 1-D Endpoints Shapesheet section.
            Visio.Cell beginCell = connector.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXForm1D,
                (short)Visio.VisCellIndices.vis1DBeginX);
            Visio.Cell endCell = connector.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXForm1D,
                (short)Visio.VisCellIndices.vis1DEndX);

            // Connect the connector end points to the from and to shapes
            beginCell.GlueToPos(fromShape, fromXPercent, fromYPercent);
            endCell.GlueToPos(toShape, toXPercent, toYPercent);
        }
Esempio n. 7
0
        private void ProcessCommand_Page_Delete(XElement pageElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            try
            {
                // TODO(crhodes):
                // Need to pass in doc so this can work for any document

                Visio.Application app = Globals.ThisAddIn.Application;

                Visio.Document doc = app.ActiveDocument;

                string pageName = pageElement.Attribute("Name").Value;

                Visio.Page deletePage = doc.Pages[pageName];

                if (deletePage != null)
                {
                    deletePage.Delete(0);
                }
            }
            catch (Exception ex)
            {
                VisioHlp.DisplayInWatchWindow(ex.ToString());
            }
        }
Esempio n. 8
0
        public static void Activate(IVisio.Document doc)
        {
            var app            = doc.Application;
            var cur_active_doc = app.ActiveDocument;

            // if the doc is already active do nothing
            if (doc == cur_active_doc)
            {
                // do nothing
                return;
            }

            // go through each window and check if it is assigned
            // to the target document
            var appwindows = app.Windows;
            var allwindows = appwindows.ToEnumerable();

            foreach (var curwin in allwindows)
            {
                if (curwin.Document == doc)
                {
                    // we did find one, so activate that window
                    // and then exit the method
                    curwin.Activate();
                    if (app.ActiveDocument != doc)
                    {
                        throw new AutomationException("failed to activate document");
                    }
                    return;
                }
            }

            // If we get here, we couldn't find any matching window
            throw new AutomationException("could not find window for document");
        }
Esempio n. 9
0
        public static void SyncPageNames()
        {
            VisioHelper.DisplayInWatchWindow(string.Format("{0}()",
                                                           System.Reflection.MethodBase.GetCurrentMethod().Name));

            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Document doc = app.ActiveDocument;

            List <Visio.Page> pagesToUpdate = new List <Microsoft.Office.Interop.Visio.Page>();

            VisioHelper.DisplayInWatchWindow(string.Format("Document({0})", doc.Name));

            foreach (Visio.Page page in doc.Pages)
            {
                if (!page.Name.Equals(page.NameU))
                {
                    pagesToUpdate.Add(page);
                }
            }

            foreach (Visio.Page page in pagesToUpdate)
            {
                Visio_Page.SyncPageNames(page);
            }
        }
Esempio n. 10
0
        public IVisio.Page Duplicate(IVisio.Document dest_doc)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            if (dest_doc == null)
            {
                throw new System.ArgumentNullException("dest_doc");
            }

            var application = this.Client.VisioApplication;

            if (application.ActiveDocument == dest_doc)
            {
                throw new VA.Scripting.ScriptingException("dest doc is same as active doc");
            }

            var src_page   = application.ActivePage;
            var dest_pages = dest_doc.Pages;
            var dest_page  = dest_pages[1];

            VA.Pages.PageHelper.Duplicate(src_page, dest_page);

            // the active window will be to the new document
            var active_window = application.ActiveWindow;

            //active_window.Page = dest_page;

            return(dest_page);
        }
Esempio n. 11
0
        private Visio.Document LoadDocument(string sPath)
        {
            Name = sPath;

            try
            {
                m_ovControl.Src = sPath;
            }
            catch (Exception e)
            {
                ReportException(e);
                return(null);
            }

            m_ovTargetDoc = m_ovControl.Document;
            m_ovTargetApp = m_ovTargetDoc.Application;

            m_ovTargetApp.Settings.ZoomOnRoll                = true;
            m_ovTargetApp.Settings.CenterSelectionOnZoom     = true;
            m_ovTargetApp.Settings.ConnectorSplittingEnabled = true;
            m_ovTargetApp.Settings.DrawingAids               = true;
            m_ovTargetApp.Settings.HigherQualityShapeDisplay = true;
            m_ovTargetApp.Settings.SmoothDrawing             = true;
            m_ovTargetApp.EventsEnabled = (short)visTF.TRUE;

            return(m_ovTargetDoc);
        }
Esempio n. 12
0
        public static void RenamePages(string searchExpression, string replacementExpression,
                                       RegexOptions regexOptions = RegexOptions.None)
        {
            VNC.Log.Trace("", Common.LOG_CATEGORY, 0);

            VisioHelper.DisplayInWatchWindow(string.Format("{0}()",
                                                           System.Reflection.MethodInfo.GetCurrentMethod().Name));

            Visio.Application app  = Globals.ThisAddIn.Application;
            Visio.Document    doc  = app.ActiveDocument;
            Visio.Page        page = app.ActivePage;

            Regex regex = new Regex(searchExpression, regexOptions);

            foreach (Visio.Shape shape in page.Shapes)
            {
                VisioHelper.DisplayInWatchWindow(string.Format("Name: {0}  Text: {1}", shape.Name, shape.Text));
                try
                {
                    string newPageName = regex.Replace(doc.Pages[shape.Text].Name, replacementExpression);

                    doc.Pages[shape.Text].Name = newPageName;
                }
                catch (Exception ex)
                {
                    Log.Error(ex, Common.LOG_CATEGORY);
                }
            }
        }
Esempio n. 13
0
 public void InitializeMember(Visio.Document visDocument)
 {
     if (this.visDocument != visDocument)
     {
         this.visDocument = visDocument;
     }
 }
Esempio n. 14
0
        public IVisio.Master Get(string master, IVisio.Document doc)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

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

            var application = this._client.Application.Get();
            var documents   = application.Documents;

            var masters = doc.Masters;

            IVisio.Master masterobj = this.TryGetMaster(masters, master);
            if (masterobj == null)
            {
                string msg = string.Format("No such master \"{0}\" in \"{1}\"", master, doc);
                throw new VisioOperationException(msg);
            }

            return(masterobj);
        }
Esempio n. 15
0
        private void ProcessCommand_Layer_Delete(XElement deleteElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            try
            {
                // TODO(crhodes):
                // Need to pass in doc and page so this can work for any document

                Visio.Application app = Globals.ThisAddIn.Application;

                Visio.Document doc = app.ActiveDocument;

                Visio.Page page = app.ActivePage;

                string layerName    = deleteElement.Attribute("Name").Value;
                string deleteShapes = deleteElement.Attribute("DeleteShapes").Value;

                Actions.Visio_Page.DeleteLayer(page, layerName, short.Parse(deleteShapes));
            }
            catch (Exception ex)
            {
                VisioHlp.DisplayInWatchWindow(ex.ToString());
            }
        }
Esempio n. 16
0
        private static void TestResize(IVisio.Document doc,
                                       VA.Drawing.Size bottomleft_margin,
                                       VA.Drawing.Size upperright_margin,
                                       VA.Drawing.Size shape_size,
                                       VA.Drawing.Size padding_size,
                                       double expected_pinx,
                                       double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PageCells();

            pagecells.PageTopMargin    = upperright_margin.Height;
            pagecells.PageBottomMargin = bottomleft_margin.Height;
            pagecells.PageLeftMargin   = bottomleft_margin.Width;
            pagecells.PageRightMargin  = upperright_margin.Width;

            var pageupdate = new VA.ShapeSheet.Update();

            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(page.PageSheet);


            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5 + shape_size.Height);

            page.ResizeToFitContents(padding_size);
            var xform = VA.Shapes.XFormCells.GetCells(shape);

            AssertVA.AreEqual(expected_pinx, expected_piny, xform.Pin(), 0.1);
            page.Delete(0);
        }
Esempio n. 17
0
        private void ProcessCommand_Page(Visio.Document doc, XElement pageElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            try
            {
                string pageName = pageElement.Attribute("Name") != null?pageElement.Attribute("Name").Value : "";

                string backgroundPageName = pageElement.Attribute("BackgroundPageName") != null?pageElement.Attribute("BackgroundPageName").Value : "";

                string isBackground = pageElement.Attribute("IsBackground") != null?pageElement.Attribute("IsBackground").Value : "0";

                if ("" != backgroundPageName)
                {
                    doc.Pages[pageName].BackPage = backgroundPageName;
                }

                doc.Pages[pageName].Background = short.Parse(isBackground);
            }
            catch (Exception ex)
            {
                VisioHlp.DisplayInWatchWindow(ex.ToString());
            }
        }
Esempio n. 18
0
        private void ProcessCommand_Page_Delete(Visio.Document doc, XElement pageElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            try
            {
                string pageName = pageElement.Attribute("Name") != null?pageElement.Attribute("Name").Value : "";

                if (pageName != "")
                {
                    Visio.Page deletePage = doc.Pages[pageName];

                    if (deletePage != null)
                    {
                        deletePage.Delete(0);
                    }
                    else
                    {
                        VisioHlp.DisplayInWatchWindow(string.Format("Page ({0}) not found", pageName));
                    }
                }
                else
                {
                    VisioHlp.DisplayInWatchWindow("Missing \"Name\" attribute");
                }
            }
            catch (Exception ex)
            {
                VisioHlp.DisplayInWatchWindow(ex.ToString());
            }
        }
Esempio n. 19
0
        private void ProcessCommand_Document(XElement documentElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            Visio.Application app = Globals.ThisAddIn.Application;

            // TODO(crhodes):
            // Add some error handling here.

            Visio.Document doc = app.Documents[documentElement.Attribute("Name").Value];

            if (documentElement.Elements("Layers").Any())
            {
                foreach (Visio.Page page in doc.Pages)
                {
                    ProcessCommand_Layers(page, documentElement.Element("Layers").Elements());
                }
            }

            if (documentElement.Elements("ShapeSheet").Any())
            {
                ProcessCommand_ShapeSheet(doc, documentElement.Element("ShapeSheet"));
            }
        }
        public void ActivateDocument(IVisio.Document doc)
        {
            var cmdtarget = this._client.GetCommandTarget(CommandTargetFlags.RequireApplication);

            // if the doc is already active do nothing
            if (doc == cmdtarget.ActiveDocument)
            {
                // do nothing
                return;
            }

            // go through each window and check if it is assigned
            // to the target document
            var allwindows = cmdtarget.Application.Windows.ToEnumerable();
            var target_win = allwindows.FirstOrDefault(w => w.Document == doc);

            if (target_win == null)
            {
                // no window found
                throw new VisioOperationException("Could not find window for document");
            }

            target_win.Activate();
            if (cmdtarget.Application.ActiveDocument != doc)
            {
                // tried to activate window, but active document does not reflect it
                throw new InternalAssertionException("Failed to activate document");
            }
        }
        public static void Run()
        {
            // ExStart:SaveDiagramTo_VDX_PDF_JPEG_withVSTO
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_KnowledgeBase();

            // Create Visio Application Object
            Visio.Application vsdApp = new Visio.Application();

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

            // Create a document object and load a diagram
            Visio.Document vsdDoc = vsdApp.Documents.Open(dataDir + "Drawing1.vsd");

            // Save the VDX diagram
            vsdDoc.SaveAs(dataDir + "SaveDiagramToVDXwithVSTO_out.vdx");

            // Save as PDF file
            vsdDoc.ExportAsFixedFormat(Visio.VisFixedFormatTypes.visFixedFormatPDF,
                                       dataDir + "SaveDiagramToPDFwithVSTO_out.pdf", Visio.VisDocExIntent.visDocExIntentScreen,
                                       Visio.VisPrintOutRange.visPrintAll, 1, vsdDoc.Pages.Count, false, true,
                                       true, true, true, System.Reflection.Missing.Value);

            Visio.Page vsdPage = vsdDoc.Pages[1];

            // Save as JPEG Image
            vsdPage.Export(dataDir + "SaveDiagramToJPGwithVSTO_out.jpg");

            // Quit Visio Object
            vsdApp.Quit();
            // ExEnd:SaveDiagramTo_VDX_PDF_JPEG_withVSTO
        }
Esempio n. 22
0
        private void addShapes2()
        {
            //this.Application.Documents.Add(@"Basic Diagram.vst");
            //<Snippet13>
            this.Application.Documents.Add("");

            Visio.Documents visioDocs    = this.Application.Documents;
            Visio.Document  visioStencil = visioDocs.OpenEx("Basic Shapes.vss",
                                                            (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);

            Visio.Page visioPage = this.Application.ActivePage;

            Visio.Master visioRectMaster = visioStencil.Masters.get_ItemU(@"Rectangle");
            Visio.Shape  visioRectShape  = visioPage.Drop(visioRectMaster, 4.25, 5.5);
            visioRectShape.Text = @"Rectangle text.";

            Visio.Master visioStarMaster = visioStencil.Masters.get_ItemU(@"Star 7");
            Visio.Shape  visioStarShape  = visioPage.Drop(visioStarMaster, 2.0, 5.5);
            visioStarShape.Text = @"Star text.";

            Visio.Master visioHexagonMaster = visioStencil.Masters.get_ItemU(@"Hexagon");
            Visio.Shape  visioHexagonShape  = visioPage.Drop(visioHexagonMaster, 7.0, 5.5);
            visioHexagonShape.Text = @"Hexagon text.";
            //</Snippet13>
        }
Esempio n. 23
0
        private void ProcessCommand_Layer_DeleteAll(XElement deleteAllElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            try
            {
                // TODO(crhodes):
                // Need to pass in doc and page so this can work for any document

                Visio.Application app = Globals.ThisAddIn.Application;

                Visio.Document doc = app.ActiveDocument;

                Visio.Page page = app.ActivePage;

                foreach (Visio.Layer layer in page.Layers)
                {
                    layer.Delete(0);
                }
            }
            catch (Exception ex)
            {
                VisioHlp.DisplayInWatchWindow(ex.ToString());
            }
        }
Esempio n. 24
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            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("Add Shapes.vdx");

            Visio.Documents visioDocs    = this.Application.Documents;
            Visio.Document  visioStencil = visioDocs.OpenEx("Basic Shapes.vss",
                                                            (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);

            Visio.Page visioPage = this.Application.ActivePage;

            Visio.Master visioRectMaster = visioStencil.Masters.get_ItemU(@"Rectangle");
            Visio.Shape  visioRectShape  = visioPage.Drop(visioRectMaster, 4.25, 5.5);
            visioRectShape.Text = @"Rectangle text.";

            Visio.Master visioStarMaster = visioStencil.Masters.get_ItemU(@"Star 7");
            Visio.Shape  visioStarShape  = visioPage.Drop(visioStarMaster, 2.0, 5.5);
            visioStarShape.Text = @"Star text.";

            Visio.Master visioHexagonMaster = visioStencil.Masters.get_ItemU(@"Hexagon");
            Visio.Shape  visioHexagonShape  = visioPage.Drop(visioHexagonMaster, 7.0, 5.5);
            visioHexagonShape.Text = @"Hexagon text.";
        }
Esempio n. 25
0
        private void ProcessCommand_Page_Add(XElement pageElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            try
            {
                // TODO(crhodes):
                // Need to pass in doc so this can work for any document

                Visio.Application app = Globals.ThisAddIn.Application;

                Visio.Document doc = app.ActiveDocument;

                string newPageName        = pageElement.Attribute("Name").Value;
                string backgroundPageName = pageElement.Attribute("BackgroundPageName").Value;
                string isBackground       = pageElement.Attribute("IsBackground").Value;

                Visio.Page newPage = Actions.Visio_Page.CreatePage(newPageName, backgroundPageName);
            }
            catch (Exception ex)
            {
                VisioHlp.DisplayInWatchWindow(ex.ToString());
            }
        }
        public static void Set_Custom_Property_on_multiple_Shapes(IVisio.Document doc)
        {
            // Set Custom Property_on_a_shape

            var page = doc.Pages.Add();
            var s1   = page.DrawRectangle(0, 0, 1, 1);
            var s2   = page.DrawRectangle(2, 2, 4, 4);

            var cp1 = new VisioAutomation.Shapes.CustomPropertyCells();

            cp1.Value = "Hello";
            VisioAutomation.Shapes.CustomPropertyHelper.Set(s1, "Propname", cp1);

            var cp2 = new VisioAutomation.Shapes.CustomPropertyCells();

            cp2.Value = "World";
            VisioAutomation.Shapes.CustomPropertyHelper.Set(s2, "Propname", cp2);

            // Retrieve all the Custom properties from multiple shapes

            var shapes = new[] { s1, s2 };
            var props  = VisioAutomation.Shapes.CustomPropertyHelper.GetCellsAsDictionary(page, shapes, CellValueType.Formula);


            // Delete the properties from the shapes
            VisioAutomation.Shapes.CustomPropertyHelper.Delete(s1, "Propname");
            VisioAutomation.Shapes.CustomPropertyHelper.Delete(s2, "Propname");

            //cleanup
            page.Delete(0);
        }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            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
            vsdDoc.SaveAs("Drawing1.vdx");
        }
Esempio n. 28
0
        private static void VerifyPageSizeToFit(IVisio.Document doc,
                                                VA.Geometry.Size bottomleft_margin,
                                                VA.Geometry.Size upperright_margin,
                                                VA.Geometry.Size shape_size,
                                                VA.Geometry.Size padding_size,
                                                double expected_pinx,
                                                double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PagePrintCells();

            pagecells.TopMargin    = upperright_margin.Height;
            pagecells.BottomMargin = bottomleft_margin.Height;
            pagecells.LeftMargin   = bottomleft_margin.Width;
            pagecells.RightMargin  = upperright_margin.Width;

            var page_writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            pagecells.SetFormulas(page_writer);

            page_writer.Commit(page.PageSheet);


            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5 + shape_size.Height);

            page.ResizeToFitContents(padding_size);
            var xform  = VA.Shapes.ShapeXFormCells.GetCells(shape, CellValueType.Result);
            var pinpos = xform.GetPinPosResult();

            Assert.AreEqual(expected_pinx, pinpos.X, 0.1);
            Assert.AreEqual(expected_piny, pinpos.Y, 0.1);
            page.Delete(0);
        }
Esempio n. 29
0
        private void ProcessCommand_ShapeSheet(Visio.Document document, XElement shapeSheetElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            foreach (XElement element in shapeSheetElement.Elements())
            {
                VisioHlp.DisplayInWatchWindow(element.ToString());
                VisioHlp.DisplayInWatchWindow(element.Name.LocalName);

                switch (element.Name.LocalName)
                {
                //case "AddPropRow":
                //    ProcessCommand_ShapeSheet_AddPropRow(shape, element);
                //    break;

                //case "AddUserRow":
                //    ProcessCommand_ShapeSheet_AddUserRow(shape, element);
                //    break;

                default:
                    VisioHlp.DisplayInWatchWindow(string.Format("Element >{0}< not supported", element.Name.LocalName));
                    break;
                }
            }
        }
Esempio n. 30
0
        public void Activate(IVisio.Document doc)
        {
            this._client.Application.AssertApplicationAvailable();

            var app            = doc.Application;
            var cur_active_doc = app.ActiveDocument;

            // if the doc is already active do nothing
            if (doc == cur_active_doc)
            {
                // do nothing
                return;
            }

            // go through each window and check if it is assigned
            // to the target document
            var allwindows = app.Windows.ToEnumerable();
            var target_win = allwindows.FirstOrDefault(w => w.Document == doc);

            if (target_win == null)
            {
                // no window found
                throw new VisioOperationException("Could not find window for document");
            }

            target_win.Activate();
            if (app.ActiveDocument != doc)
            {
                // tried to activate window, but active document does not reflect it
                throw new InternalAssertionException("Failed to activate document");
            }
        }
Esempio n. 31
0
        public static void AddFooter()
        {
            VisioHelper.DisplayInWatchWindow(string.Format("{0}()",
                                                           System.Reflection.MethodBase.GetCurrentMethod().Name));

            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Document doc = app.ActiveDocument;

            // TODO: Add some stuff to read from config file with a dialog to default the selection

            //doc.HeaderLeft = "";
            //doc.HeaderCenter = "&n";
            //doc.HeaderRight = "";

            doc.FooterLeft   = "&f&e";
            doc.FooterCenter = "";
            doc.FooterRight  = "&d &p-&P";

            var font = doc.HeaderFooterFont;

            font.Size = (decimal)8;

            doc.HeaderFooterFont = font;

            var size = doc.HeaderFooterFont.Size;
        }
Esempio n. 32
0
 public void NewDocument()
 {
     var docs = this.Application.Documents;
     this.doc = docs.Add("");
     this.stencil = docs.OpenStencil("basic_u.vss");
     var masters = stencil.Masters;
     this._masterRectangle = masters["Rectangle"];
 }
Esempio n. 33
0
        public VisioGraph(ProgressWindow progressWindow, ProcessViewerDialog parent)
        {
            try
            {
                var drawItem = parent.Result;
                _vapp = new Visio.InvisibleApp();

                if (!IsCorrectVisioVersion(_vapp))
                    return;

                _progressWindow = progressWindow;

                _vdoc = _vapp.Documents.Add("");

                if (!File.Exists(_vapp.Path + @"1033\Concept.vss"))
                {
                    File.Delete(_vapp.Path + @"1033\Concept.vss");
                    File.WriteAllBytes(_vapp.Path + @"1033\Concept.vss", Properties.Resources.Concept);
                }

                _stencil = _vapp.Documents.OpenEx(_vapp.Path + @"1033\Concept.vss", (short)Visio.VisOpenSaveArgs.visOpenDocked | (short)Visio.VisOpenSaveArgs.visOpenRO | (short)Visio.VisOpenSaveArgs.visAddStencil);

                _vdoc.Pages[1].Name = "Overview Page";

                _parent = parent;

                _bgWorker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true };
                _bgWorker.DoWork += DoWork;
                _bgWorker.RunWorkerCompleted += RunWorkerCompleted;
                _bgWorker.ProgressChanged += ProgressChanged;

                _progressWindow.pbarTotal.Minimum = 0;

                int totalOperations = 0;
                foreach (var process in drawItem.Process)
                {
                    process.GenerateContent(drawItem.ConnectionString);
                    totalOperations += process.SubProcesses.Count();
                    totalOperations += process.Connectors.Count();
                }

                int stepSize = totalOperations / 20;

                _progressWindow.pbarTotal.Maximum = (totalOperations) + stepSize;

                var args = new WorkerArgs
                               {
                                   DrawItem = drawItem,
                                   StepSize = stepSize,
                               };

                _bgWorker.RunWorkerAsync(args);
            }
            catch (Exception)
            {
                MessageBox.Show(@"Unable to load Visio. Please make sure Visio 2010 has been installed on your system.");
            }
        }
Esempio n. 34
0
        public DocumentComparer(Visio.Application app, Visio.Document documentA, Visio.Document documentB)
        {
            _documentA = documentA;
            _documentB = documentB;
            _resultingDocument = app.Documents.Add("");

            //visio creates an initial (I call it "nil") page
            //just in case there are any more, give the same a guid name
            //these pages are removed at the end.
            if (_resultingDocument.Pages.Count > 0)
            {
                foreach (Visio.Page page in _resultingDocument.Pages)
                {
                    page.Name = Guid.NewGuid().ToString();
                    _guidsOfNilPages.Add(page.Name);
                }
            }

            _app = app;
        }
Esempio n. 35
0
 public IVisio.Document Render(IVisio.Application app)
 {
     var appdocs = app.Documents;
     IVisio.Document doc = null;
     if (this.vst_template_file == null)
     {
         doc = appdocs.Add("");
     }
     else
     {
         const int flags = 0; // (int)IVisio.VisOpenSaveArgs.visAddDocked;
         const int langid = 0;
         doc = appdocs.AddEx(this.vst_template_file, this.measurementSystem, flags, langid);
     }
     this.VisioDocument = doc;
     var docpages = doc.Pages;
     var startpage = docpages[1];
     this.Pages.Render(startpage);
     return doc;
 }
Esempio n. 36
0
 public void NewDocument(double w, double h)
 {
     var docs = this.Application.Documents;
     this.doc = docs.Add("");
 }