L
LadySnowWhite
I am writing a C# program to generate diagrams in Visio. So far, I have been
using the following article for assistance, and it has been a great help
(http://msdn.microsoft.com/en-us/library/aa722522.aspx). But there is one
issue I don’t know how to resolve and that is how to specify where the
connection lines connect on the shape. In the article’s example, everything
is just randomly dropped and connected dynamically to the nearest connection
point. I need to be able to specify which connection point a like links to.
For example, if I have two boxes (A and B) and I need three connections (1,
2, and 3). Connection 1 needs to come out of the right side of Box A and
connect to the top side of Box B. Connection 2 also needs to come out of the
right side of Box A and connect to the left side of Box B. Connection 3
needs to come out of the left side of Box B and loop back to go into the top
side of Box B.
I am using the following code to glue the shapes and connectors:
private static void glueConnectionToItems(
Visio.Page drawingPage,
Visio.Shape connectionShape,
int fromShapeIndex,
int toShapeIndex)
{
try
{
// Glue the beginning of the connection to the "From" shape.
Visio.Cell shapeCell =
drawingPage.Shapes[fromShapeIndex].get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXFormOut,
(short)Visio.VisCellIndices.visXFormPinX);
Visio.Cell connectorCell =
connectionShape.get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXForm1D,
(short)Visio.VisCellIndices.vis1DBeginX);
connectorCell.GlueTo(shapeCell);
// Glue the end of the connection to the "To" shape.
shapeCell =
drawingPage.Shapes[toShapeIndex].get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXFormOut,
(short)Visio.VisCellIndices.visXFormPinX);
connectorCell =
connectionShape.get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXForm1D,
(short)Visio.VisCellIndices.vis1DEndX);
connectorCell.GlueTo(shapeCell);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I suspect that I should be able to adjust the connection points via the
above methods, but so far nothing I’ve tried has worked. Is anyone more
familiar with these functions who can better explain how I can accomplish
this? Thanks!
using the following article for assistance, and it has been a great help
(http://msdn.microsoft.com/en-us/library/aa722522.aspx). But there is one
issue I don’t know how to resolve and that is how to specify where the
connection lines connect on the shape. In the article’s example, everything
is just randomly dropped and connected dynamically to the nearest connection
point. I need to be able to specify which connection point a like links to.
For example, if I have two boxes (A and B) and I need three connections (1,
2, and 3). Connection 1 needs to come out of the right side of Box A and
connect to the top side of Box B. Connection 2 also needs to come out of the
right side of Box A and connect to the left side of Box B. Connection 3
needs to come out of the left side of Box B and loop back to go into the top
side of Box B.
I am using the following code to glue the shapes and connectors:
private static void glueConnectionToItems(
Visio.Page drawingPage,
Visio.Shape connectionShape,
int fromShapeIndex,
int toShapeIndex)
{
try
{
// Glue the beginning of the connection to the "From" shape.
Visio.Cell shapeCell =
drawingPage.Shapes[fromShapeIndex].get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXFormOut,
(short)Visio.VisCellIndices.visXFormPinX);
Visio.Cell connectorCell =
connectionShape.get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXForm1D,
(short)Visio.VisCellIndices.vis1DBeginX);
connectorCell.GlueTo(shapeCell);
// Glue the end of the connection to the "To" shape.
shapeCell =
drawingPage.Shapes[toShapeIndex].get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXFormOut,
(short)Visio.VisCellIndices.visXFormPinX);
connectorCell =
connectionShape.get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXForm1D,
(short)Visio.VisCellIndices.vis1DEndX);
connectorCell.GlueTo(shapeCell);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I suspect that I should be able to adjust the connection points via the
above methods, but so far nothing I’ve tried has worked. Is anyone more
familiar with these functions who can better explain how I can accomplish
this? Thanks!