我正在以编程方式在visio中绘制UML图,其中我使用动态连接器来连接shapes.But有些情况下连接器穿过形状而不是通过页面(即连接器从源头开始路径)通过位于源和目的地之间的另一个形状到目的地形状),我希望连接器只能通过页面。请建议如何使这成为可能。
答案 0 :(得分:1)
你必须从C#翻译,但这就是我在做的方式:
/// <summary>Attaches two Visio shapes to each other with the specified connector object.</summary>
/// <param name="shape1">Visio shape to connect from.</param>
/// <param name="shape2">Visio shape to connect to.</param>
/// <param name="connector">Visio line shape that will connect shape1 to shape2.</param>
/// <param name="straight">Whether this connector should be a straight line</param>
[CLSCompliant(false)]
protected static void ConnectShapes(
Visio.Shape shape1,
Visio.Shape shape2,
Visio.Shape connector,
bool straight = false)
{
try
{
// get the cell from the source side of the connector
Visio.Cell beginXCell = connector.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.CellsSRC[(short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX]);
// get the cell from the destination side of the connector
Visio.Cell endXCell = connector.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.CellsSRC[(short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX]);
if (straight)
{
connector.CellsU["ConLineRouteExt"].ResultIUForce = (double)Visio.VisCellVals.visLORouteExtStraight;
connector.CellsU["ShapeRouteStyle"].ResultIUForce = (double)Visio.VisCellVals.visLORouteCenterToCenter;
}
else
{
// THIS IS WHAT YOU ARE LOOKING FOR
connector.CellsU["ConLineRouteExt"].ResultIUForce = (double)Visio.VisCellVals.visLORouteExtNURBS;
connector.CellsU["ShapeRouteStyle"].ResultIUForce = (double)Visio.VisCellVals.visLORouteRightAngle;
}
}
catch (Exception e)
{
throw (e);
}
}