Using automation to remove items from a drawing

J

John Reed

I have a group enclosed in a shape - the "enclosing" shapes part of the
group. I want to take the group and ungroup them. After ungrouping I want to
select the "enclosing" shape and delete it or move it or whatever.. Is there
any way to use automation to select this enclosing shape?

That is, any way besides iteratively moving and checking that I am "inisde"
the shape?

Thanks
 
B

Bill K. [MSFT]

There are several ways to handle this, depending on what you want to do.

1) Before a shape is ungrouped you can cache the list of its contained
shapes.
such as:
Public Sub UngroupSelection()
Dim shpGroup As Visio.Shape
Dim shpChild As Visio.Shape
Dim colChildShapes As New Collection

Set shpGroup = ActiveWindow.Selection(1)
For Each shpChild In shpGroup.Shapes
colChildShapes.Add shpChild
Debug.Print "Child Shape: " & shpChild.Name
Next shpChild

shpGroup.Ungroup
For Each shpChild In colChildShapes
' update the shape...
Next shpChild
End Sub


2) You can use the ShapeParentChanged or QueryCancelUngroup event (much less
code than the above sample).
Private Sub Document_ShapeParentChanged(ByVal Shape As IVShape)
Debug.Print "Parent Changed " & Shape.Name, Shape.ContainingShape.Name
End Sub

There are also several methods for determining if a shape is contained by
(ie. overlapping) another shape independent of grouping.
Take a look at the HitTest, SpatialNeighbors, and SpatialQuery methods in
the developer documentation for details.


Hope this helps,
 
S

Scott LeGendre

How about naming the shapes in some uniform manner and
selecting them by name?

Scott

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