Export Business Process shapes as a list

C

celtic_kiwi

I am a VBA hack and have tried off this group, Visio help, and MSDN to
meet my seemingly simple requirements. I apologise if this is a no
brainer for you but it has me confused.

I have a business process diagram, well lots of them really, with
rectangles, decision points an some other boxes on them.
Each shape has one or more connectors/lines running between.

All I want is to produce a list similar to the following:
ShapeID, ShapeText, LinkDir, LinkTo, LinkText

ShapeID is the shape.id
ShapeText is shape.text
LinkDir is the direction of the link (Out/in)
LinkTo is the Shape.id of the connected rectangle, Decision, etc
LinkText is the shape.text for the line/connector running between

I do not need to know how the connection connects to either shape,
just that it does
I can clean up any line breaks in the Text property myself

I hacked together the following from the sources listed above but just
cant get the output I want

All help much appreciated.

Public Sub ToPart_Example()

Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim intToData As Integer
Dim strTo As String
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeID As Integer
Dim intCounter As Integer

Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeID = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeID)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to
'and the part of the shape it connects to,
'and print that information in the Immediate window.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet
intToData = vsoConnect.toPart

'Print the name and part of the shape the
'Connect object connects to.
Debug.Print vsoShape.ID & "|" & vsoShape.ObjectType & "|" &
vsoShape.Name & "|" & vsoShape.Text & "|To|" & vsoConnectTo.ID & "|" &
vsoConnectTo_ObjectType & "|" & vsoConnectTo.Name & "|" &
vsoConnectTo.Text & "||"

Next intCounter

Next intCurrentShapeID

End Sub
 
J

JuneTheSecond

A thing I first noticed is, I hope may not be a cause.
Set vsoShape = vsoShapes(intCurrentShapeID)
should be
Set vsoShape = vsoShapes.ItemFromId(intCurrentShapeID)
 
M

Mark Nelson [MS]

This part is OK. The code is working with the shape INDEX, not the ID. The
variable name is wrong, but that doesn't prevent the code from executing.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Nelson [MS]

I'll be the first to say that walking Visio connections should be much
easier than it is today. I strongly encourage you to review the sample code
in the Visio SDK on connectivity.

The problem with the code below is that you don't account for the difference
between 2-D shapes and 1-D connectors. In Visio, connectors are glued to
shapes. Shapes are not glued to connectors (under most circumstances).
When you ask for the Connects collection on a Shape object, you are asking
what that object is glued to - something that only makes sense if the Shape
object is a connector. Shape.Connects.Count on a 2-D shape is typically 0.
For a 2-D shape, ask for the FromConnects collection. This asks Visio, "who
is connected to me?". When iterating through the page's Shapes collection,
you are iterating through both 2-D shapes and 1-D connectors. You probably
don't need both.


--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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