如何以编程方式在visio中重新路由连接器?

时间:2019-03-25 07:17:28

标签: c# vba visio visio-vba

我正在为visio 2013开发VSTO加载项。我需要重新路由连接器,因为该图很复杂并且包含很多步骤。自动布线的连接器没有清晰的路径。有什么方法可以通过编程方式重新路由连接器吗?就像在visio应用程序中手动拖动连接器点一样。

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

1 个答案:

答案 0 :(得分:0)

由于我需要做类似的事情,因此您启发了我对此进行破解。 这是我发现使其工作的一种方法。该子例程引用连接器的形状,隐藏自动布线的线,添加新的几何图形节,然后手动调整该节中的几个点(基于原始可见线的高度/宽度百分比)。您显然可以通过程序调整数量/位置。

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。 (这可能会为您提供所需的内容,但需要进行一些修补)。