If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#11
|
|||
|
|||
".Connects" member
Public Sub ImmediateNeighbours()
Dim vsoConnect As Visio.Connect Dim vsoConnects As Visio.Connects Dim vsoSelect As Visio.Selection Dim vsoShape As Visio.Shape Dim vsoShapes As Visio.Shapes Dim vsoShapeTo As Visio.Shape Dim intCounter As Integer Set vsoSelect = Visio.ActiveWindow.Selection vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper Debug.Print vsoSelect.Count If vsoSelect.Count 0 Then For Each vsoShape In vsoSelect Set vsoConnects = vsoShape.FromConnects For Each vsoConnect In vsoConnects Set vsoShapeTo = vsoConnects.ToSheet.Connects Debug.Print vsoShape.Text; " connects to "; vsoShapeTo.Text Next vsoConnect Next vsoShape Else MsgBox "You Must Have Something Selected" End If Close #1 End Sub |
#13
|
|||
|
|||
".Connects" member
That was the first thing I tried. I have experimented with a ton of
iterations and I tried to post the original one I thought made sense but I guess I made that typo. vsoConnect.ToSheet.Connects gives the type mismatch. |
#14
|
|||
|
|||
".Connects" member
vsoConnect vs vsoConnects - one letter, big difference
I would tend to replace with For Each vsoConnect In vsoShape.FromConnects John... Visio MVP "Paul Herber" wrote in message ell.net... On Wed, 18 Feb 2009 10:07:00 -0800 (PST), wrote: Public Sub ImmediateNeighbours() Dim vsoConnect As Visio.Connect Dim vsoConnects As Visio.Connects Dim vsoSelect As Visio.Selection Dim vsoShape As Visio.Shape Dim vsoShapes As Visio.Shapes Dim vsoShapeTo As Visio.Shape Dim intCounter As Integer Set vsoSelect = Visio.ActiveWindow.Selection vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper Debug.Print vsoSelect.Count If vsoSelect.Count 0 Then For Each vsoShape In vsoSelect Set vsoConnects = vsoShape.FromConnects For Each vsoConnect In vsoConnects Set vsoShapeTo = vsoConnects.ToSheet.Connects Set vsoShapeTo = vsoConnect.ToSheet.Connects -- Regards, Paul Herber, Sandrila Ltd. Electronics Packages for Visio http://www.electronics-packages.sandrila.co.uk/ |
#15
|
|||
|
|||
".Connects" member
Set vsoConnects = vsoShape.From Connects
For Each vsoConnect In vsoConnects ----- Is identical to: ----- For Each vsoConnect In vsoShape.FromConnects ----- |
#16
|
|||
|
|||
".Connects" member
wrote in message
... Set vsoConnects = vsoShape.From Connects For Each vsoConnect In vsoConnects ----- Is identical to: ----- For Each vsoConnect In vsoShape.FromConnects ----- It is, but it has one less variable (that can be easily confused) to deal with and dispose of. The less clutter the easier it is to read what the code is doing. Some of the examples on the Visio VBA page use the "For i = 1 to count" structure and I should take some time and simplify it to "For Each" structures. John... Visio MVP |
#17
|
|||
|
|||
".Connects" member
Ahh okay. I misunderstood you before, I thought you were proposing a
solution to the .Connects problem. It's always a good idea to minimize the amount of code written out, thank you. |
#18
|
|||
|
|||
".Connects" member
I created a small drawing (two shapes connected by one connector) and ran
your sample against it. Actually, I updated it a little : Sub TestMac() Dim vsoSelect As Visio.Selection Dim vsoShape As Visio.Shape Dim vsoConnects As Visio.Connects Dim vsoConnect As Visio.Connect Set vsoSelect = Visio.ActiveWindow.Selection vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper Debug.Print vsoSelect.Count For Each vsoShape In vsoSelect Debug.Print vsoShape.Name Set vsoConnects = vsoShape.Connects Debug.Print vsoConnects.Count Next vsoShape End Sub The key here is that the info for vsoSelect.Count doesn't change, so I pulled it out of the loop through the selection. Then I added a line to print the shape name. Here is the output that I get : 3 Dynamic connector 2 Decision 0 Process 0 This makes sense, as there are 3 objects in the selection. Then we see the name of each item, followed by the count of connections. The Dynamic Connector is the only connector on the page, so it is to only non-zero number, and it should be 2, since it connects to two shapes. If you want to play with a great example of the use of Connects versus FromConnects, I suggest installing the SDK (if you haven't already) and searching the Visio Code Samples Library for "Drawing Navigator Using Connections". There are samples for VB, VB.Net, and C#, and it is a great demonstration of these properties, and how to 'walk' a drawing using the connections information : "Description: This sample drops a set of shapes that are connected to each other in a hierarchical fashion on a page and then walks through each shape from a starting shape, using the begin and end points of the Dynamic connectors." You are on the right track - try my version of your sample code in a simple drawing, to see if you observe similar results to mine. Then you can test out the Navigator sample to explore further. Barb Way Product Support - Visio Microsoft Corporation [This posting is provided "As Is" with no warranties, and confers no rights.] -------------------- Sub TestMac() Dim vsoSelect As Visio.Selection Dim vsoShape As Visio.Shape Dim vsoConnects As Visio.Connects Dim vsoConnect As Visio.Connect Set vsoSelect = Visio.ActiveWindow.Selection vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper For Each vsoShape In vsoSelect Debug.Print vsoSelect.Count Set vsoConnects = vsoShape.Connects Debug.Print vsoConnects.Count Next vsoShape End Sub ----- The vsoShape.Connects line is returning 0 every time. If I use the FromConnects member instead of Connects, it returns the correct number. I need to access the Connects however, as I need to find the actual shapes that each shape in my selection connect to. Does anyone know what I am missing? Thanks in advance. |
|
Thread Tools | |
Display Modes | |
|
|