【问题标题】:How to reroute the connector in visio programmatically?如何以编程方式重新路由 visio 中的连接器?
【发布时间】:2019-08-15 09:39:08
【问题描述】:

我正在为 visio 2013 开发 VSTO 插件。我需要重新路由连接器,因为图表很复杂并且包含很多步骤。自动布线的连接器没有明确的路径。有没有办法以编程方式重新路由连接器?就像在 visio 应用程序中手动拖动连接点一样。

我阅读了一些 vba 文档 https://docs.microsoft.com/en-us/office/vba/api/visio.connect 但没有一个能给我洞察力。

【问题讨论】:

  • 由 Visio 应用程序核心管理的动态连接器,我们没有任何文档说明它是如何工作的!您可以“正确(根据您的需要)”重新路由,但 Visio 核心可以更改您的更改,并创建新路径!
  • 那么,您的意思是说,在我更改为动态连接器之后,Visio 应用程序核心最终可能会更改它吗?此外,是否有任何关于重新路由动态连接器的示例或文档?
  • 是的,Visio 核心可以改变连接器的路由!您可以阅读相同的russian speaking thread via Google Translate
  • 您可以以编程方式重新布局页面,这将强制所有连接器进入清晰的路径。它可能会导致一些看起来像意大利面条的图表,但可以通过巧妙地了解放置形状的顺序来最大限度地减少这种情况。这是您要寻找的吗?
  • 谢谢你们。 SmrtGrunt,你真的用一种新方法启发了我。但我仍然想弄清楚如何路由动态连接器的路径,我的意思是,除了 fromShape 和 toShape 的点之外,为动态连接器定义一些点,然后它的路径将是一条线,依次路径所有这些点。代理人,谢谢你的链接,我会在完成我的工作后看看。抱歉耽搁了,我最近很忙。

标签: c# vba visio


【解决方案1】:

你启发了我尝试解决这个问题,因为我需要做类似的事情。 这是我发现的一种使它起作用的方法。此子例程引用连接器形状,隐藏自动布线的线,添加新的几何部分,并手动调整该部分中的几个点(基于原始可见线的百分比高度/宽度)。您显然可以通过编程方式调整数量/位置。

Sub CustomRoutedConnector(shpConnectorShape As Shape)

    With shpConnectorShape
        'Hide the automatically routed connector line (still there, just hidden)
        .CellsSRC(visSectionFirstComponent, 0, 2).FormulaU = "TRUE"

        'Make a custom geometry section
        .AddSection visSectionFirstComponent + 1
        .AddRow visSectionFirstComponent + 1, visRowComponent, visTagComponent
        .AddRow visSectionFirstComponent + 1, visRowVertex, visTagLineTo
        .AddRow visSectionFirstComponent + 1, visRowVertex, visTagMoveTo

        'Set up the new geometry section rows (11,1 and 11,2 are the start and end rows)
        .CellsSRC(11, 0, 0).FormulaForceU = "TRUE"
        .CellsSRC(11, 0, 1).FormulaForceU = "FALSE"
        .CellsSRC(11, 0, 2).FormulaForceU = "FALSE"
        .CellsSRC(11, 0, 3).FormulaForceU = "FALSE"
        .CellsSRC(11, 0, 5).FormulaForceU = "FALSE"
        .CellsSRC(11, 1, 0).FormulaU = "0"
        .CellsSRC(11, 1, 1).FormulaU = "0"
        .CellsSRC(11, 2, 0).FormulaU = "0"
        .CellsSRC(11, 2, 1).FormulaU = "0"

        'Add two additional rows for demonstration (could be programatically 
        'adjusted to however many points you need)

        .AddRow visSectionFirstComponent + 1, 2, visTagLineTo
        .CellsSRC(11, 2, 0).FormulaU = "0"
        .CellsSRC(11, 2, 1).FormulaU = "0"

        .AddRow visSectionFirstComponent + 1, 3, visTagLineTo
        .CellsSRC(11, 3, 0).FormulaU = "0"
        .CellsSRC(11, 3, 1).FormulaU = "0"

        'Adjust the geometry of the rows (the doubles given are percentages of the height/width of the original connector)
        'I recommend stepping through this to see how it moves the points:
        .CellsSRC(visSectionFirstComponent + 1, 2, 0).FormulaU = ".5"
        .CellsSRC(visSectionFirstComponent + 1, 3, 0).FormulaU = ".5"
        .CellsSRC(visSectionFirstComponent + 1, 3, 1).FormulaU = ".5"
        .CellsSRC(visSectionFirstComponent + 1, 4, 0).FormulaU = "1"
        .CellsSRC(visSectionFirstComponent + 1, 4, 1).FormulaU = "1"

    End With

End Sub

此自定义路线的终点仍与起点和终点形状相关联。要完全终止所有自动路由,请使用 .LayoutRoutePassive property of the page。 (这可能会为您提供所需的内容,但需要进行一些修改)。

【讨论】:

  • 由于某种原因,这里的代码突出显示不是很好,但它应该可以复制/粘贴。
  • 非常感谢您关注我的问题。你给的答案很棒。然而,这个探索是我的可行性测试中的不确定点之一。而现在,它显示出太多难以解决的问题。我把你的答案存起来了,如果再次出现同样的需求,我会深入研究一下。
  • @stevenchuh 不用担心。我希望它对您或将来的其他人有所帮助。
猜你喜欢
  • 2018-09-15
  • 1970-01-01
  • 2013-10-16
  • 1970-01-01
  • 2012-08-13
  • 2012-12-20
  • 1970-01-01
  • 1970-01-01
  • 2021-09-12
相关资源
最近更新 更多