enumerating shapes in three containers on the same page

Started by RSut, November 25, 2010, 06:15:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RSut

I am having trouble enumerating shapes in a set of three containers on the same page. The problem probably my weak understanding of object syntax.
MSDN: http://msdn.microsoft.com/en-us/library/ff959245.aspx tells me that to enumerate shapes in containers I use this syntax:

For Each memberID In vsoContainerShape.ContainerProperties.GetMemberShapes(visContainerFlagsDefault)
   Set vsoShape = vsoPage.Shapes.ItemFromID(memberID)
   ' Insert additional code here.
Next

So- I set up 3 containers on the active page. The top one had two shapes in it (sphObj.texts = 'Root1' and 'Root2'), the second contained 'Root7' & the last container 'Root3'. Containers were identified in an enumeration of shapes in the following sub, through the presence of the "User.msvStructureType" shapesheet cell.: The problem is shown in the immediate window output - only the first container was reported with contents. The second container was reported, without content, and the third container was not reported. Something went wrong at the point of the second cycle of 'GetMemberShapes'. The debug feedback highlit the code line including 'GetMemberShapes' and reported: "Invalid parameter".  The Object~Browser gave me no clues that I recognised. Could someone explain and point me to a bit of text that will educate me in this type of skill? Safe to assume near-tubula rasa. Thanks!!

Sub contShps()
Dim pagObj As Visio.Page
Dim shpsObj As Visio.Shapes
Dim shpObj As Visio.Shape
Dim celObj As Visio.Cell
Dim vsoContainerShape As Visio.Shape
Dim vsoShape As Visio.Shape
Dim memberID As Variant
Dim i As Integer
Dim d As String

Set pagObj = ActivePage
Set shpsObj = pagObj.Shapes
For i = 1 To shpsObj.Count
   Set shpObj = shpsObj(i)
   d = ""
   If shpObj.CellExists("User.msvStructureType", Visio.visExistsAnywhere) Then
       Set celObj = shpObj.Cells("User.msvStructureType")
       d = celObj.ResultStr("")
       Debug.Print "Container = "; shpObj.Text
       Debug.Print "i = "; i
       Set vsoContainerShape = shpObj
           For Each memberID In vsoContainerShape.ContainerProperties.GetMemberShapes(visContainerFlagsDefault)
               Set vsoShape = ActivePage.Shapes.ItemFromID(memberID)
               Debug.Print vsoShape.Text
           Next
   ElseIf d = "" Then
       Debug.Print "Shape = "; shpObj.Text
   End If
Next i
End Sub

The immediate window:
Container = Cont 1
i =  1
Root1
Root2
Container = Cont2
i =  2

RSut

RSut responds to own question..
David Parker has provided code that reports on container category and shapes present:
http://davidjpp.wordpress.com/2009/09/07/visio-2010-containment-and-cross-functional-flowcharts/
This worked first time for me.

??? Can someone refer me to a good source to understand how arrays are used to handle/extract data from enumerations of office objects? For example, the is no requirement to ReDim arrays in these enumerations - I can see that. Where can I access a detailed account of the nitty gritty principles?

PS: In the above reference, David Parker also provides code to determine is what container a selected shape is located.

RSut

aledlund

As an observation from the side, your question is less about office and more about arrays. The idiosyncracies of array behavior can often be specific to the language your using to access them. Since your reference uses vba, you might check this out.

http://msdn.microsoft.com/en-us/library/aa164778(office.10).aspx

al