public void DuplicateInExcel()
        {
            Visio.Window win = vApp.ActiveWindow;
            if (win.Type != (short)Visio.VisWinTypes.visDrawing)
            {
                return;
            }
            if (win.Selection.Count < 1)
            {
                return;
            }

            xRulerOrigin = vApp.ActivePage.PageSheet.Cells["XRulerOrigin"].Result[Visio.VisUnitCodes.visMillimeters];
            yRulerOrigin = vApp.ActivePage.PageSheet.Cells["YRulerOrigin"].Result[Visio.VisUnitCodes.visMillimeters];

            Excel.Application xlsApp    = new Excel.Application();
            Excel.Workbook    workbook  = xlsApp.Workbooks.Add();
            Excel.Worksheet   worksheet = workbook.Worksheets[1];
            worksheet.Name        = "Positions";
            worksheet.Cells[1, 1] = "X";
            worksheet.Cells[1, 2] = "Y";
            Excel.ListObject listObject = worksheet.ListObjects.Add(Excel.XlListObjectSourceType.xlSrcRange, worksheet.Range[worksheet.Cells[1, 1], worksheet.Cells[1, 2]], null, Excel.XlYesNoGuess.xlYes);

            xlsApp.WorkbookBeforeClose += new Excel.AppEvents_WorkbookBeforeCloseEventHandler(App_WorkbookBeforeClose);

            worksheet.Columns.AutoFit();
            xlsApp.Visible = true;
        }
Esempio n. 2
0
        /// <summary>
        /// ReSize - resize all selected objects to the same height and/or width of the primary selection
        /// </summary>
        /// <param name="Height">Boolean.  If true, resize all objects to be the same height.</param>
        /// <param name="Width">Boolean.  If true, resize all objects to be the same width.</param>
        private void ReSize(bool Height, bool Width)
        {
            // Grab a reference to the current active window
            Visio.Window aw = vApp.ActiveWindow;

            // Iterate over each selected shape
            foreach (Visio.Shape x in aw.Selection)
            {
                // Only bother resizing items other than the PrimaryItem
                if (x != aw.Selection.PrimaryItem)
                {
                    // Only resize the width if Width is true.
                    // Additionaly, only resize if the widths currently differ.
                    // This way, Ctrl-Z becomes a little more friendly (without this
                    // extra check, the resize to the same width would cause Ctrl-Z
                    // to appear to have no effect, requiring Ctrl-Z to be pressed
                    // an additional time.
                    if (Width && x.Cells["Width"].ResultIU != aw.Selection.PrimaryItem.Cells["Width"].ResultIU)
                    {
                        x.Cells["Width"].ResultIU = aw.Selection.PrimaryItem.Cells["Width"].ResultIU;
                    }

                    // Same thing for Height.
                    if (Height && x.Cells["Height"].ResultIU != aw.Selection.PrimaryItem.Cells["Height"].ResultIU)
                    {
                        x.Cells["Height"].ResultIU = aw.Selection.PrimaryItem.Cells["Height"].ResultIU;
                    }
                }
            }
        }
Esempio n. 3
0
        private static void SetViewRectToSelection(IVisio.Window window,
                                                   IVisio.VisBoundingBoxArgs bbargs,
                                                   double padding_scale)
        {
            if (padding_scale < 0.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(padding_scale));
            }

            if (padding_scale > 1.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(padding_scale));
            }

            var app           = window.Application;
            var active_window = app.ActiveWindow;
            var sel           = active_window.Selection;
            var sel_bb        = sel.GetBoundingBox(bbargs);

            var delta     = sel_bb.Size * padding_scale;
            var view_rect = new Drawing.Rectangle(sel_bb.Left - delta.Width, sel_bb.Bottom - delta.Height,
                                                  sel_bb.Right + delta.Height, sel_bb.Top + delta.Height);

            window.SetViewRect(view_rect);
        }
Esempio n. 4
0
        private void WindowOnSelectionChanged(Visio.Window window)
        {
            SaveEditorToShape();

            _editorShape = _window.Selection.PrimaryItem;
            ReloadEditor();
        }
Esempio n. 5
0
 public static void SetWindowRect(
     this IVisio.Window window,
     System.Drawing.Rectangle rect)
 {
     // MSDN: http://msdn.microsoft.com/en-us/library/office/ff769098.aspx
     window.SetWindowRect(rect.Left, rect.Top, rect.Width, rect.Height);
 }
Esempio n. 6
0
        /// <summary>
        /// Метод инвертирования ребра
        /// </summary>
        /// <param name="window"></param>
        public void Invert(Visio.Window window)
        {
            if (window != null)
            {
                // Для всех выделенных фигур
                foreach (Visio.Shape shape in window.Selection)
                {
                    // Проверяем, что это ребро
                    if (edges.ContainsValue(shape))
                    {
                        foreach (var edge in edges)
                        {
                            if (edge.Value == shape)
                            {
                                // Инвертируем ребро
                                Visio.Cell beginXCell = shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DBeginX);
                                beginXCell.GlueTo(vertices[edge.Key.Destination].get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX));
                                Visio.Cell endXCell = shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DEndX);
                                endXCell.GlueTo(vertices[edge.Key.Source].get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX));

                                // Заменяем старое ребро новым инвертированным
                                DotEdge <string> invertedEdge = new DotEdge <string>(edge.Key.Destination, edge.Key.Source, edge.Key.Attributes);
                                break;
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Допустимо только инвертирование ребер!");
                    }
                }
            }
        }
Esempio n. 7
0
        public static bool AddAnchorWindowToVisio(Visio.Application visApplication, string strCaption,
                                                  int iAnchorMode, bool bAutoHide, bool bVisible,
                                                  int iLeft, int iTop, int iWidth, int iHeight,
                                                  string strMergeID, string strMergeClass, int iMergePosition,
                                                  ref Visio.Window visWindowToAdd)
        {
            Visio.Window visActiveWindow, visNewWindow;
            bool         bSuccess = false;
            int          iWindowState, iWindowType;

            visActiveWindow = visApplication.ActiveWindow;
            if (visActiveWindow != null)
            {
                iWindowState = iAnchorMode;
                if (bAutoHide)
                {
                    iWindowState = (int)iWindowState | (int)Visio.VisWindowStates.visWSAnchorAutoHide;
                }
                if (bVisible)
                {
                    iWindowState = (int)iWindowState | (int)Visio.VisWindowStates.visWSVisible;
                }
                iWindowType = (int)Visio.VisWinTypes.visAnchorBarAddon;
                AddWindow(visActiveWindow, strCaption, iWindowState, iWindowType,
                          iLeft, iTop, iWidth, iHeight, strMergeID, strMergeClass, iMergePosition,
                          out visNewWindow);
                if (visNewWindow != null)
                {
                    visWindowToAdd = visNewWindow;
                    bSuccess       = true;
                }
            }
            return(bSuccess);
        }
        /// <summary>
        /// Shows or hides panel for the given Visio window.
        /// </summary>
        /// <param name="window">Target Visio diagram window where to show/hide the panel</param>
        public void TogglePanel(Visio.Window window)
        {
            if (window == null)
            {
                return;
            }

            var panelFrame = FindWindowPanelFrame(window);

            if (panelFrame == null)
            {
                panelFrame = new PanelFrame(new TheForm(window));
                panelFrame.CreateWindow(window);

                panelFrame.PanelFrameClosed += OnPanelFrameClosed;
                _panelFrames.Add(window.ID, panelFrame);
            }
            else
            {
                panelFrame.DestroyWindow();
                _panelFrames.Remove(window.ID);
            }
            $if$($uiCallbacks$ == true)
            ThisAddIn.UpdateUI();
            $endif$
        }
Esempio n. 9
0
 public ReverseManager(Visio.Window window, ThisAddIn addinInstance, string filePath)
 {
     InitializeComponent();
     synchronizationContext = SynchronizationContext.Current;
     this._window           = window;
     this._addin            = addinInstance;
     this._filePath         = filePath;
     currentForm            = this;
     currentForm.Width      = 1010;
     currentForm.Height     = 570;
     picStatus.Width        = 995;
     picStatus.Height       = 339;
     picStatus.Top          = 11;
     lblClose.Left          = 962;
     lblDetails.Top         = 417;
     lblDetails.Width       = 995;
     lblDetails.Height      = 144;
     lblStatus.Height       = 67;
     lblStatus.Width        = 995;
     lblStatus.Top          = 350;
     panel1.Width           = 1010;
     panel1.Height          = 570;
     currentForm.Show();
     bgDeployLocally.RunWorkerAsync();
 }
 private void OnPanelFrameClosed(Visio.Window window)
 {
     _panelFrames.Remove(window.ID);
     $if$($uiCallbacks$ == true)
     ThisAddIn.UpdateUI();
     $endif$
 }
Esempio n. 11
0
 public static void SetViewRect(
     this IVisio.Window window,
     VA.Drawing.Rectangle rect)
 {
     // MSDN: http://msdn.microsoft.com/en-us/library/office/ms367542(v=office.14).aspx
     window.SetViewRect(rect.Left, rect.Top, rect.Width, rect.Height);
 }
Esempio n. 12
0
 /// <summary>
 /// Form constructor, receives parent Visio diagram window
 /// </summary>
 /// <param name="window">Parent Visio diagram window</param>
 public PanelForm(Visio.Window window, ThisAddIn addinInstance)
 {
     _window        = window;
     _addinInstance = addinInstance;
     InitializeComponent();
     RefreshData();
 }
Esempio n. 13
0
 public static void Select(
     this IVisio.Window window,
     IEnumerable <IVisio.Shape> shapes,
     IVisio.VisSelectArgs selectargs)
 {
     VisioAutomation.Windows.WindowHelper.Select(window, shapes, selectargs);
 }
Esempio n. 14
0
 // イベントハンドラー
 private void Application_BeforeWindowClosed(Visio.Window Window)
 {
     if (this.Task != null && !this.Task.IsCompleted)
     {
         this.Task.Cancel();
         this.ApplicationClosed = true;
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Align - aligns all selected objects to the same top/middle/bottom and/or left/center/right
        /// </summary>
        /// <param name="Horizontal">VisHorizontalAlignTypes indicating left/center/right</param>
        /// <param name="Vertical">VisVerticalAlignTypes indicating top/middle/bottom</param>
        private void Align(Visio.VisHorizontalAlignTypes Horizontal, Visio.VisVerticalAlignTypes Vertical)
        {
            // Grab a reference to the current active window
            Visio.Window aw = vApp.ActiveWindow;

            // Use built-in Align function
            aw.Selection.Align(Horizontal, Vertical, false);
        }
Esempio n. 16
0
 public void ActivateShape(Visio.Shape shape)
 {
     Visio.Document doc          = axDrawingControl1.Document;
     Visio.Window   activeWindow = doc.Application.ActiveWindow;
     activeWindow.Zoom = 0.85;
     activeWindow.CenterViewOnShape(shape, Visio.VisCenterViewFlags.visCenterViewSelectShape);
     this.Show();
 }
Esempio n. 17
0
        int shapesCount;        //DateTime date;
        //CultureInfo ci = new CultureInfo(language);
        //string shortDateFormat = ci.DateTimeFormat.ShortDatePattern;
        public SearchDialog()
        {
            //Shapes shapes;
            InitializeComponent();
            var app = Globals.ThisAddIn.Application;
            docu = app.ActiveDocument;
            //language = 1031;
            page = docu.Pages[1];
            window = app.ActiveWindow;        }        //private void listBoxControl1_SelectedIndexChanged(object sender, EventArgs e)
        PanelFrame FindWindowPanelFrame(Visio.Window window)
        {
            if (window == null)
            {
                return(null);
            }

            return(_panelFrames.ContainsKey(window.ID) ? _panelFrames[window.ID] : null);
        }
Esempio n. 19
0
        public static System.Drawing.Rectangle GetWindowRect(this IVisio.Window window)
        {
            // MSDN: http://msdn.microsoft.com/en-us/library/office/ms367542(v=office.14).aspx
            int left, top, height, width;

            window.GetWindowRect(out left, out top, out width, out height);
            var r = new System.Drawing.Rectangle(left, top, width, height);

            return(r);
        }
Esempio n. 20
0
        public void OnBeforeWindowClosed(Visio.Window visWindow)
        {
            string strCaption;

            strCaption = visWindow.Caption;
            if (strCaption.Contains("Vue 3D"))
            {
                addinApplication.BabylonClose();
            }
        }
Esempio n. 21
0
 public static void Select(
     this IVisio.Window window,
     IEnumerable <IVisio.Shape> shapes,
     IVisio.VisSelectArgs selectargs)
 {
     foreach (var shape in shapes)
     {
         window.Select(shape, (short)selectargs);
     }
 }
Esempio n. 22
0
        /// <summary>
        /// Event handler called after a different page is activated. Loads the
        /// appropriate stencil for this page.
        /// </summary>
        /// <param name="Window"></param>
        private void app_WindowTurnedToPage(Visio.Window Window)
        {
            string activePage  = app.ActivePage.Name;
            string stencilPath = CaseTypes.stencilPath();

            // Not all pages has an associated stencil
            bool stencilExists = true;

            switch (activePage)
            {
            case CaseTypes.OBJECT_PAGE:
                stencilPath += CaseTypes.OBJECT_STENCIL;
                break;

            case CaseTypes.RELATION_PAGE:
                stencilPath += CaseTypes.RELATION_STENCIL;

                HashSet <string> currentPageShapes = new HashSet <string>();
                foreach (Visio.Shape s in app.ActivePage.Shapes)
                {
                    currentPageShapes.Add(s.NameU);
                }

                foreach (Visio.Page p in Window.Document.Pages)
                {
                    if (p.Name == CaseTypes.OBJECT_PAGE)
                    {
                        foreach (var item in Utilities.getAllShapesOnPage(p))
                        {
                            if (!currentPageShapes.Contains(item.NameU))
                            {
                                item.Copy(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
                                app.ActivePage.Paste(Visio.VisCutCopyPasteCodes.visCopyPasteNormal);
                            }
                        }
                        break;
                    }
                }
                break;

            case CaseTypes.FLOW_PAGE:
                stencilPath += CaseTypes.FLOW_STENCIL;
                break;

            default:
                stencilExists = false;
                break;
            }

            if (stencilExists)
            {
                app.Documents.OpenEx(stencilPath,
                                     (short)Visio.VisOpenSaveArgs.visOpenDocked);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Event handler called before a different page is activated. Unloads
        /// all docked stencil windows.
        /// </summary>
        /// <param name="Window"></param>
        private void app_BeforeWindowPageTurn(Visio.Window Window)
        {
            Visio.Documents docs = app.Documents;

            foreach (Visio.Document d in docs)
            {
                if (d.Type == Visio.VisDocumentTypes.visTypeStencil)
                {
                    d.Close();
                }
            }
        }
Esempio n. 24
0
 public static bool GetVisActiveWindow(Visio.Application visApp, ref Visio.Window visWindowDoc)
 {
     try
     {
         visWindowDoc = visApp.ActiveWindow;
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Esempio n. 25
0
        /// <summary>
        /// 导出visio的Page中的所有形状到word中
        /// </summary>
        /// <param name="Page">要进行粘贴的Visio中的页面</param>
        /// <param name="range">此时word文档中的全局range的位置或者范围</param>
        /// <remarks>在此方法中,会将visio指定页面中的所有形状进行选择,然后进行组合,最后将其输出到word中;
        /// 由局部安全的原则,在进行绘图前,将另起一行,并将段落样式设置为“图片”样式</remarks>
        private void Export_VisioPlanview(Page Page, ref Word.Range range)
        {
            Microsoft.Office.Interop.Visio.Application app = Page.Application;
            //
            Window wnd = default(Window);

            wnd      = app.ActiveWindow;
            wnd.Page = Page;


            wnd.Activate();
            //这里要将ShowChanges设置为True,否则下面的SelectAll()方法会被禁止。
            app.ShowChanges = true;
            wnd.SelectAll();
            //  ---------------------- 耗时代码1:复制Visio的Page中的所有形状
            //而且在这一步的时候Visio的窗口中可能会弹出子窗口
            wnd.Selection.Copy();
            //这一步也可能会导致Visio的窗口中弹出子窗口
            wnd.DeselectAll();

            //关闭所有的子窗口
            //Debug.Print(app.ActiveWindow.Windows.Count)     ‘即使只显示出一个子窗口,这里也会返回10
            //For Each subWnd As Visio.Window In app.ActiveWindow.Windows
            //    subWnd.Visible = False
            //Next

            //根据实际情况:每次都只弹出“外部数据”这一子窗口,所以在这里就只对其进行单独隐藏。
            wnd.Windows.ItemFromID((Int32)Visio.VisWinTypes.visWinIDExternalData).Visible = false;

            //让窗口的显示适应页面
            wnd.ViewFit = (Int32)Visio.VisWindowFit.visFitPage;
            Word.Range with_2 = range;
            //新起一行,并设置新段落的段落样式为图片
            NewLine(range, ParagraphStyle.picture);

            //  ---------------------- 耗时代码2:将Visio的Page中的所有形状粘贴到Word中(不可以用:DataType:=23)
            with_2.PasteSpecial(DataType:  Word.WdPasteDataType.wdPasteOLEObject, Placement: Word.WdOLEPlacement.wdInLine);


            Word.InlineShape shp = default(Word.InlineShape);
            range.Select();
            range.Application.Selection.MoveLeft(Unit: Word.WdUnits.wdCharacter, Count: 1,
                                                 Extend: Word.WdMovementType.wdExtend);
            shp = range.Application.Selection.InlineShapes[1];
            //约束图形的宽度,将其限制在word页面的正文宽度之内
            WidthRestrain(shp, ContentWidth);

            //刷新visio屏幕
            app.ShowChanges = true;
        }
Esempio n. 26
0
        /// <summary>
        /// Метод выделения вершин
        /// </summary>
        /// <param name="key"></param>
        /// <param name="window"></param>
        public void Select(int key, Visio.Window window)
        {
            if (window != null)
            {
                window.DeselectAll();
                switch (key)
                {
                // Выделить все вершины
                case 1:
                    foreach (var node in vertices)
                    {
                        window.Select(node.Value, 2);
                    }
                    break;

                // Выделить все соединенные вершины
                case 2:
                    foreach (var node in vertices)
                    {
                        if (node.Value.ConnectedShapes(Visio.VisConnectedShapesFlags.visConnectedShapesAllNodes, "").Length != 0)
                        {
                            window.Select(node.Value, 2);
                        }
                    }
                    break;

                // Выделить все несоединенные вершины
                case 3:
                    foreach (var node in vertices)
                    {
                        if (node.Value.ConnectedShapes(Visio.VisConnectedShapesFlags.visConnectedShapesAllNodes, "").Length == 0)
                        {
                            window.Select(node.Value, 2);
                        }
                    }
                    break;

                // Выделить все ребра
                case 4:
                    foreach (var edge in edges)
                    {
                        window.Select(edge.Value, 2);
                    }
                    break;

                default:
                    throw new ArgumentException("Ключ не соответствует допустимому диапозону");
                }
            }
        }
Esempio n. 27
0
        public static void Select(
            this IVisio.Window window,
            IEnumerable <IVisio.Shape> shapes,
            IVisio.VisSelectArgs selectargs)
        {
            if (shapes == null)
            {
                throw new System.ArgumentNullException("shapes");
            }

            foreach (var shape in shapes)
            {
                window.Select(shape, (short)selectargs);
            }
        }
Esempio n. 28
0
        public static VA.Drawing.Rectangle GetViewRect(this IVisio.Window window)
        {
            // MSDN: http://msdn.microsoft.com/en-us/library/office/ff765846.aspx
            double left, top, height, width;

            window.GetViewRect(out left, out top, out width, out height);
            double x0 = left;
            double x1 = left + width;
            double y0 = top - height;
            double y1 = y0 + height;

            var r = new VA.Drawing.Rectangle(x0, y0, x1, y1);

            return(r);
        }
Esempio n. 29
0
        /// <summary>
        /// Form constructor, receives parent Visio diagram window
        /// </summary>
        /// <param name="window">Parent Visio diagram window</param>
        public TheForm(Visio.Window window)
        {
            _window = window;
            InitializeComponent();

            webBrowser.ObjectForScripting = this;

            Win32.DisableClickSounds(true);

            webBrowser.DocumentCompleted += WebBrowserOnDocumentCompleted;
            _window.SelectionChanged     += WindowOnSelectionChanged;

            _editorShape = _window.Selection.PrimaryItem;
            ReloadEditor();

            Closed += OnClosed;
        }
Esempio n. 30
0
 private void Application_SelectionChanged(Visio.Window Window)
 {
     if (!_isAddingAShape)
     {
         ActionsRibbon   rib       = Globals.Ribbons.ActionsRibbon;
         Visio.Selection selection = Window.Selection;
         foreach (dynamic item in selection)
         {
             Visio.Shape shp = item as Visio.Shape;
             if (shp != null)
             {
                 shp.Characters.Text = "selected";
                 shp.CellsSRC[(short)Visio.VisSectionIndices.visSectionObject, 3, 0].FormulaU = $"THEMEGUARD(RGB({rib.Red}, {rib.Green}, {rib.Blue}))";
             }
         }
     }
     _isAddingAShape = false;
 }