Пример #1
0
 public void CreateShape(Visio.Application VApp, Visio.IVDocument drawingDocument)
 {
     Visio_shape = VisioInterface.CreateVisioShape(VApp, drawingDocument, X_coord, Y_coord, stencilName, masterNameU);
     if (Visio_shape == null)
     {
         DebugEx.WriteLine(string.Format("Error creating Visio shape for {0}", FullName));
     }
 }
Пример #2
0
        //CONNECT TO SHAPES
        public static Visio.IVShape CreateVisioShape(Visio.Application vApp, Visio.IVDocument drawingDocuemnt, double X_in, double Y_in, string stencilName, string masterNameU)
        {
            // Find the stencil in the Documents collection by name.
            Visio.IVDocuments visioDocuments = vApp.Documents;
            Visio.IVShape     droppedShape   = null;
            Visio.IVMaster    masterInStencil;

            Visio.IVPage page = drawingDocuemnt.Pages.First();

            //get width and height of the sheet
            double Sheet_Width  = page.PageSheet.get_CellsU("PageWidth").ResultIU;
            double Sheet_Height = page.PageSheet.get_CellsU("PageHeight").ResultIU;

            Sheet_Width  = Sheet_Width - 3;
            Sheet_Height = Sheet_Height - 3;

            Visio.IVDocument stencil;
            try
            {
                stencil = visioDocuments[stencilName];
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                // The stencil is not in the collection; open it as a
                // docked stencil.
                stencil = visioDocuments.OpenEx(stencilName, (short)VisOpenSaveArgs.visOpenDocked);
            }

            // Get a master from the stencil by its universal name.
            try
            {
                masterInStencil = stencil.Masters.get_ItemU(masterNameU);
                double actual_xposition = (Sheet_Width * X_in) + 2;
                double actual_yposition = (Sheet_Height * Y_in) + 2;
                droppedShape = page.Drop(masterInStencil, actual_xposition, actual_yposition);
            }
            catch (Exception Ex)
            {
                System.Windows.Forms.MessageBox.Show(string.Format("Cannot create Visio shape. Error is : {0} {1}", Ex.Message, Ex.InnerException?.Message), "Visio interface error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            return(droppedShape);
        }