Programmatically link connectors to different connection points on

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!
 
D

David Parker

You appear to be connecting to the PinX cell, which means you will get
Dynamic Glue.
If you want Static Glue, then the shapeCell should be the ConnectionPoint
cell


LadySnowWhite said:
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!
 
L

LadySnowWhite

David,

Thank you for replying. Do you know what the function is to connect to the
shapeCell instead of the PinX cell?

Thanks.


David Parker said:
You appear to be connecting to the PinX cell, which means you will get
Dynamic Glue.
If you want Static Glue, then the shapeCell should be the ConnectionPoint
cell


LadySnowWhite said:
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!

--
David Parker
Microsoft MVP (Visio)
http://bvisual.spaces.live.com
http://www.visualizinginformation.com
 
D

David Parker

It is the same method, GlueTo, but you just need to chnage the arguments of
get_CellsSRC to refer to a Connection Point cell. Intellisense should lead
you there....

LadySnowWhite said:
David,

Thank you for replying. Do you know what the function is to connect to
the
shapeCell instead of the PinX cell?

Thanks.


David Parker said:
You appear to be connecting to the PinX cell, which means you will get
Dynamic Glue.
If you want Static Glue, then the shapeCell should be the ConnectionPoint
cell


message
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!

--
David Parker
Microsoft MVP (Visio)
http://bvisual.spaces.live.com
http://www.visualizinginformation.com
 
L

LadySnowWhite

Dear KIRSCHNER,

To post a new thread, go to the “Visio General Questions†section. Near the
top of the page, just under the “Search For:†area is a toolbar. The first
button on the left is to start a new thread. Next to that is a dropdown menu
that says, “Select new post.†Under the options you may post a question,
suggestion, or general comment. Selecting one of those should make a pop up
window appear for you to add you new posting information. I hope you get it
to work okay; good luck.

~LadySnowWhite~
 
L

LadySnowWhite

Dear David,

I appreciate your comments; however, I think the objective is far more
complicated than you think. So far, nothing you’ve suggested has been
implementable. I am currently still investigating some solutions and I’ll
post back if I find something that works. Thanks again for your input.

~LadySnowWhite~


David Parker said:
It is the same method, GlueTo, but you just need to chnage the arguments of
get_CellsSRC to refer to a Connection Point cell. Intellisense should lead
you there....

LadySnowWhite said:
David,

Thank you for replying. Do you know what the function is to connect to
the
shapeCell instead of the PinX cell?

Thanks.


David Parker said:
You appear to be connecting to the PinX cell, which means you will get
Dynamic Glue.
If you want Static Glue, then the shapeCell should be the ConnectionPoint
cell


message
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!


--
David Parker
Microsoft MVP (Visio)
http://bvisual.spaces.live.com
http://www.visualizinginformation.com

--
David Parker
Microsoft MVP (Visio)
http://bvisual.spaces.live.com
http://www.visualizinginformation.com
 
L

LadySnowWhite

I finally found a working solution!

I replaced my previous code with the following code. The Indicy methods did
not need to be changed, those must stay right where they are.What needed to
be changed was ALL 3 METHODS FOLLOWING Section Indicies, Row Indicies, and
Cell Indicies to the appropriate methods for Connection Points. AND for the
method, “visRowConnectionPts,†you can add a “+n†where n = Connection point
ID number. This allows you to specify exact which connection point to attach
the connector.

I hope this post can help anyone else who may be struggling with the same
thing.


private static void glueConnectionToSourceItems(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.visSectionConnectionPts,
//specify to use connection points
(short)Visio.VisRowIndices.visRowConnectionPts+1, //select which
connection pt to use: +1 = connection pt #1
(short)Visio.VisCellIndices.visCnnctDirX); // connect to that
point using either CnnctA or CnnctDirX
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.visSectionConnectionPts,
//specify to use connection points
(short)Visio.VisRowIndices.visRowConnectionPts+2, //select which
connection pt to use: +2 = connection pt #2
(short)Visio.VisCellIndices.visCnnctDirX); //connect to that
point using either CnnctA or CnnctDirX
connectorCell =
connectionShape.get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowXForm1D,
(short)Visio.VisCellIndices.vis1DEndX);
connectorCell.GlueTo(shapeCell);
}
catch (Exception ex)
{
MessageBox.Show("My glueConnectionToSourceItems error " + ex.Message);
}
}// end GlueTo


~LadySnowWhite~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top