首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Visio二次开发(二)----Shape的添加和连接

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

作者头像
令仔很忙
发布2018-09-14 16:23:53
9010
发布2018-09-14 16:23:53
举报
文章被收录于专栏:令仔很忙令仔很忙令仔很忙

先说一说为什么我要用到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);

下面展示一下效果:

这里写图片描述
这里写图片描述
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015年09月29日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档