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