Connection-maker macro?

M

Mac

lets say you have a layer with 20 objects in it and you want to connect them
in an N:N fashion (20, objs, that makes 190 connections, duh...).

A) Can you think of a code to do this? I doubt this is achievable via a
single macro...is it?

B)I've been thinking of a variation for a macro - first you select some of
those objects then run a macro which does like - go to this layer, take what
is selected there and make them connected. But now when I think about it,
approaches A and B are not that diffferent...:-D

Can anybody help?
 
C

Chris Roth [MVP]

Hi Mac,

Have a look at this code snippet. Maybe it will help:

Sub NNConnections()

Dim shpFrom As Visio.Shape, shpTo As Visio.Shape, shpConn As Visio.Shape,
shp As Visio.Shape
Dim collShapes As Collection
Dim i As Integer, j As Integer
Dim pg As Visio.Page
Dim shps As Visio.Shapes
Dim objConn As Variant

'// Get a page:
Set pg = Visio.ActivePage

'// Set page routing style to center-to-center:
pg.PageSheet.CellsSRC(visSectionObject, visRowPageLayout,
visPLORouteStyle).FormulaForceU = "16"

'// Add all the non-connector shapes to a VB collection:
Set collShapes = New Collection
Set shps = pg.Shapes
For Each shp In shps
If shp.OneD = False Then
Call collShapes.Add(shp)
End If
Next

Set objConn = Visio.Application.ConnectorToolDataObject

'// Loop through the shapes in the shapes collection:
For i = 1 To collShapes.Count

Set shpFrom = collShapes.Item(i)

For j = i + 1 To collShapes.Count

Set shpTo = collShapes.Item(j)

'// Connect shpFrom to shpTo:
Set shpConn = pg.Drop(objConn, 0, 0)
Call shpConn.CellsU("BeginX").GlueTo(shpFrom.CellsU("PinX"))
Call shpConn.CellsU("EndX").GlueTo(shpTo.CellsU("PinX"))

Next j

Next i

End Sub


--
Hope this helps,

Chris Roth
Visio MVP

Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
 
M

Mac

Hi Chris,

this is it, thank you so much! Just one more question: all of these conns go
directly to the Connector layer. Is it possible to programmatically specifiy
which layer (or create a new one in one command) should they go to?
Mac
 

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