deleting shapes from container

Started by perry59, November 22, 2020, 11:17:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

perry59

I need to be able to Programmatically delete shapes from a container.
attempting to do so manually results in a protection error, so I assume I'll get the same through code.
can anyone tell me how to accomplish this?
thanks!
what, me worry?

OldSchool1948

Try this

Private Sub deleteContainerShapes()

    Dim vsoPage As Visio.Page
    Set vsoPage = Visio.ActivePage
   
    Dim vsoSelection As Visio.Selection
    Set vsoSelection = Visio.ActiveWindow.Selection
   
    If vsoSelection.Count = 0 Then
        MsgBox "Nothing Selected"
        Exit Sub
    End If
   
    Dim i As Integer
    For i = 1 To vsoSelection.Count
   
        Dim vsoContainer As Visio.Shape
        Set vsoContainer = vsoSelection(i)
       
        '// Unlock the group
        vsoContainer.Cells("LockGroup").formula = "=0"
   
        '// Get the Shape IDs of all Container Shapes
        Dim ShapeIDs() As Long
        ShapeIDs = vsoContainer.ContainerProperties.GetMemberShapes(visContainerFlagsDefault)
                   
        Dim s As Integer
        For s = LBound(ShapeIDs) To UBound(ShapeIDs)
           
            '// Get each container shape
            Dim vsoContainerShp As Visio.Shape
            Set vsoContainerShp = vsoPage.Shapes.ItemFromID(ShapeIDs(s))
           
            '// Remove Delete Protection
            vsoContainerShp.Cells("LockDelete").formula = "=0"
            vsoContainerShp.Delete
           
        Next s
       
    Next i
   
End Sub


perry59

I didn't even realize that dropping shapes into a container made them part of a "group".
all I had to do was clear the protection on the container, delete the shape that was in it, then put the protection back.
easy peasy!
thanks
what, me worry?

perry59

Sorry, but it seems this was all for naught.
I am new to "containers"
you don't need to do anything special to delete a shape from a container, just delete it.
my problem was I was dropping shapes onto a container (which contained a group to represent a D-sub connector) those shapes were becoming part of the GROUP, not members of the container.
I was not calling ContainerProperties.AddMember. so later if one or more of those shapes needed to be deleted, nothing showed up in the call to ContainerProperties.GetMemberShapes

I need to restructure my code :(
what, me worry?