2-D Shapes connection points

H

ha1o

Hi, I need to connect two 2-DShapes by code on a Visio DrawingControl object.

The shapes I need to connect are "Cabinet" and "558329-1".

The shape "558329-1" has a category named "1-D endPoints". I tried to use
the same code I used to connect a "Dynamic Connector" shape; but it didn't
work.

Cell beginX = shape558329-1.get_CellsSRC(
(short)Microsoft.Office.Interop.Visio.
VisSectionIndices.visSectionObject,
(short)Microsoft.Office.Interop.Visio.
VisRowIndices.visRowXForm1D,
(short)Microsoft.Office.Interop.Visio.
VisCellIndices.vis1DBeginX);

beginX.GlueTo(shapeCabinet.get_CellsSRC(
(short)Microsoft.Office.Interop.Visio.
VisSectionIndices.visSectionObject,
(short)Microsoft.Office.Interop.Visio.
VisRowIndices.visRowXFormOut,
(short)Microsoft.Office.Interop.Visio.
VisCellIndices.visXFormPinX));


Then I tried to learnd about Inward/outward connection points, but I still
cannot connect those shapes by code.

Hope you can help me with this. Thks
 
J

JuneTheSecond

I wonder if Visio has get_CellsSRC method. is it speciality in C# ?
and 2D-shape does not have beginX cell.
do you mean connection point?
a connection point might be accessed by
visSectionConnectionPts, visRowConnectionPts + i, visX
 
A

Al Edlund

is this a rack diagram? have you possibly renamed the connection points in
the 'cabinet' to something like "shelf_left_10" for the connection point on
the left side of shelf 10?
al
 
H

ha1o

Hi Al

Yes I'm trying to show a rack diagram. And I was able to change the
connection points to "shelf_left_10"; but I still can't find a instruction
that glue those points.

My application keeps throwing an error that says "Inappropriate source for
this action". Even with the instruction tha June told me.
 
A

Al Edlund

I use vb in my work, but maybe this will help you.

al


first you might want to make the connection points in the rack a little more
friendly. I use this to rename them
'

' go through a rack and add connection point names so that

' we can address at a shelf level

'

Public Sub RenameRackShelfRows(ByVal visShape As Visio.Shape)

Dim visSection As Visio.Section

Dim visRow As Visio.Row

Dim strShelfName As String

Set visSection = visShape.Section(visSectionConnectionPts)


Dim intX As Integer

Dim intY As Integer

Dim intShelf As Integer

Dim rowName As String

rowName = ""

' connections start at zero

For intX = 0 To visSection.Count - 1

Set visRow = visSection.Row(intX)

strShelfName = "shelf_"

intY = (intX + 1) Mod 2 ' are we odd or even

If intY = 0 Then

intShelf = ((intX + 1) / 2)

strShelfName = strShelfName & "right_"

Else

intShelf = (intX / 2) + 1

strShelfName = strShelfName & "left_"

End If

visRow.NameU = strShelfName & CStr(intShelf)

visRow.Name = strShelfName & CStr(intShelf)

Next intX



End Sub

Once I have that done I can insert the shapes using this



'

' given the page, rack name, component name, and slot install the

' component in the rack

'

Public Sub InstallComponentInRack _

(ByVal visPage As Visio.Page, _

ByVal strRack As String, _

ByVal strComponent As String, _

ByVal intSlot As Integer)

Dim visShapes As Visio.Shapes

Dim visShape As Visio.Shape

Dim visCell As Visio.Cell

Dim strRight As String

strRight = "shelf_right_"

Dim strLeft As String

strLeft = "shelf_left_"

strRight = strRight & CStr(intSlot)

strLeft = strLeft & CStr(intSlot)

InstallComponent visPage, strComponent, strRack, strLeft, strRight



End Sub



'

' pass in the page, the parent component, the component to install, and

' two connection points, this is the base for installing

'

Public Sub InstallComponent _

(ByVal visPage As Visio.Page, _

ByVal strComponent As String, _

ByVal strParent As String, _

ByVal strParent_1 As String, _

ByVal strParent_2 As String)

Dim visShapes As Visio.Shapes

Dim visShape As Visio.Shape

Dim visCell As Visio.Cell

Dim strBeginX As String

Dim strEndX As String

Dim strBeginY As String

Dim strEndY As String

Dim strConnection As String

On Error GoTo InstallComponent_err

Set visShapes = visPage.Shapes

Set visShape = visShapes.ItemU(strParent)

strConnection = "Connections." & strParent_1

If visShape.CellExists(strConnection, False) = False Then

MsgBox "connection one does not exist " & strParent_1

End If

strConnection = "Connections." & strParent_2

If visShape.CellExists(strConnection, False) = False Then

MsgBox "connection two does not exist " & strParent_2

End If

' build the cell formulas for connecting component to correct cabinet

' and shelf. Visio 12 gets confused with some names if they

' are not delimited by an appostrophe

strBeginX = "PAR(PNT('" & strParent & "'!Connections." & strParent_1 &
".X,'" & strParent & "'!Connections." & strParent_1 & ".Y))"

strEndX = "PAR(PNT('" & strParent & "'!Connections." & strParent_2 & ".X,'"
& strParent & "'!Connections." & strParent_2 & ".Y))"

strBeginY = "PAR(PNT('" & strParent & "'!Connections." & strParent_1 &
".X,'" & strParent & "'!Connections." & strParent_1 & ".Y))"

strEndY = "PAR(PNT('" & strParent & "'!Connections." & strParent_2 & ".X,'"
& strParent & "'!Connections." & strParent_2 & ".Y))"



Set visShape = visShapes.ItemU(strComponent)

If visShape.CellExists("BeginX", False) = True Then

Set visCell = visShape.Cells("BeginX")

visCell.Formula = strBeginX

End If

If visShape.CellExists("EndX", False) = True Then

Set visCell = visShape.Cells("EndX")

visCell.Formula = strEndX

End If

If visShape.CellExists("BeginY", False) = True Then

Set visCell = visShape.Cells("BeginY")

visCell.Formula = strBeginY

End If

If visShape.CellExists("EndX", False) = True Then

Set visCell = visShape.Cells("EndY")

visCell.Formula = strEndX

End If


Exit Sub


InstallComponent_err:

MsgBox Err.Description

End Sub
 

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