构建 VISIO 插件以通过创建矩形并在其中包含文本来显示有关形状选择的相关数据

Building a VISIO addin to show relevent data on shape selection by creating rectangle and include text in it

Visio.Page visioPage = this.Application.ActivePage;
//Create a rectangle
Visio.Shape details = visioPage.DrawRectangle(45, 45, 45, 45);
Visio.Selection selection = Window.Selection;
            foreach (dynamic item in selection)
            {
                Visio.Shape shp = item as Visio.Shape;
                if (shp != null)
                {  
                   //Dropping Rectangle on to the page
                   visioPage.Drop(details, 50, 50);
                }
 }

尝试使用上面的代码在 Application_SelectionChanged 事件中的 visio 上创建一个矩形。但是,无法在 Visio 上看到矩形。请在这里指出错误或任何有关相同的指示。

您的矩形似乎具有零宽度和高度。这可能是原因吗? DrawRectangle 接受 x1, y1, x2, y2 坐标。

缺少 VisioStencil。

 Visio.Documents visioDocs = this.Application.Documents;
    // Get Basic Shapes Stencil
     Visio.Document visioStencil = visioDocs.OpenEx("Basic Shapes.vss",
                (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
    //Get Rectangle Shape
    Visio.Master visioRectMaster = visioStencil.Masters.get_ItemU(@"Rectangle");
    // Add Shape to Page
    Visio.Shape visioRectShape = visioPage.Drop(visioRectMaster, rectX, rectY);
    visioRectShape.NameU = "ShapeName";