Visio二次开发(二)----Shape的添加和连接

     先说一说为什么我要用到Visio的二次开发,现在做的项目设计到了一些电子地图,下面的这张图片是美工画的一张地铁里面门禁布局图,而这些图在做项目的时候是需要用Visio画的,有提前画好的直接加载到项目中就可以使用,但是有些是需要通过代码也就是二次开发来实现的!
这里写图片描述

     下面说说具体的实现过程:

     shape的添加

     你只需要找到相应的模板,模板下的形状,就可以加载形状,没有什么困难的,如果你实在不知道,那么就学者去用用Visio宏,对你的学习很有帮助(Visio二次开发(一)—-巧用Visio宏

'''新建一个documents集合'''
 Visio.Documents visDocs = adcVisio.Document.Application.Documents;
'''加载模板并将其加载到一个停靠的窗口中'''
 Visio.Document visStencil = visDocs.OpenEx("BASIC_M.VSS", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
'''加载一个当前活动的Page绘图区域'''
Visio.Page visPage = adcVisio.Document.Application.ActivePage;

'''加载三角形'''
Visio.Master visioRectMaster = visStencil.Masters.get_ItemU(@"Triangle");
Visio.Shape visioRectShape = visPage.Drop(visioRectMaster, 3.25, 4.5);
'''加载圆形'''
Visio.Master visioRect1Master = visStencil.Masters.get_ItemU(@"Square");
Visio.Shape visioRect1Shape = visPage.Drop(visioRect1Master, 1.25, 2.5);
'''加载动态链接线'''
Visio.Master visioWallMaster = visStencil.Masters.get_ItemU(@"Line-curve connector");
Visio.Shape visioWallShape = visPage.Drop(visioWallMaster, 5.5, 6.5);

     Shape的连接

     从上面的途中可以看出,两个门Shape之间有的是通过线连接的,那么我们能够通过代码来实现连接的功能吗?当然,必须的可以:

 ''' <summary>'''
 ''' 将两个形状进行连接'''
 ''' </summary>'''
 '''<param name="shape1"></param>'''
 ''' <param name="shape2"></param>'''
 ''' <param name="connector"></param>'''
 private static void ConnectShapes(Visio.Shape shape1, Visio.Shape shape2, Visio.Shape connector)
     {
        ''' get the cell from the source side of the connector '''
        Cell beginXCell = connector.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXForm1D,
                (short)Visio.VisCellIndices.vis1DBeginX);
       '''glue the source side of the connector to the first shape '''
       beginXCell.GlueTo(shape1.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXFormOut,
                (short)Visio.VisCellIndices.visXFormPinX));
       ''' get the cell from the destination side of the connector'''
       Cell endXCell = connector.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXForm1D,
                (short)Visio.VisCellIndices.vis1DEndX);
      ''' glue the destination side of the connector to the second shape '''

       endXCell.GlueTo(shape2.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXFormOut,
                (short)Visio.VisCellIndices.visXFormPinX));
        }

     然后再在定义形状的代码下边加上一句话

'''将两个图形用动态链接线链接起来'''
ConnectShapes(visioRectShape, visioRect1Shape, visioWallShape);

     下面展示一下效果:

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值