Lock shape position within a group?

Started by smoore33, April 17, 2021, 06:57:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

smoore33

What is the best way to prevent shapes within a group from being moved relative to the group, while still being able to move the group itself? Thanks.

wapperdude

There are two ways, both work equally well.
1) Using the ribbon:  Select sub-shape, then Developer tab > Protection.  Select the X- and Y-Position entries.  Do for each shape within the group.

2) Using ShapeSheet.  Select sub-shape and open ShapeSheet.  In the Shape Transform section, add the guard function around the PinX and PinY entries.  Do for each shape within the group.
Visio 2019 Pro

smoore33

Thanks. Do both methods lock the shapes' X- and Y-positions relative to the group. So if the group is moved, the X- and Y-coordinates relative to the new group position are the same as the X- and Y-coordinates were relative to the old group position? (There must be a better way to say that!)

Also is there an easy way to select all shapes within a group, without having to select them one-by-one?

wapperdude

I think it would've been quicker if you had tried the solutions... but,, yes.  That's how it works.

Not sure of the intent of "selecting all", but in this particular scenario, it won't work with either approach option presented.  Has to be applied, one shape at a time.  If there are a lot of changes to be done, perhaps quicker to write a bit of code to do the work.
Visio 2019 Pro

smoore33

This could be an inefficient workflow, but (for example) to create masters, I develop the shapes on a separate drawing page, select all shapes, protect them, group them, protect the group, then save the whole thing as a master. If I could select all subshapes at the same time as selecting the group, it would save some time. If I want to change the protection, I have to do it at each "level" and it gets more tedious, if the group itself also contains groups. So I was hoping to be able to drag a selection box around the whole thing and make settings changes that would affect all objects at all levels within the selection box...for example to be able to unprotect everything.

wapperdude

Unfortumately, it doesn't work that way.  Here's simple bit of code that shows how to protect the positions as indicated previously.  If you had multiple groups on a single page, it would take care of each one, one at a time.

Sub LockSubs()
    Dim vShp As Visio.Shape
    Dim i as integer
   
    ActiveWindow.DeselectAll
   
    For Each vShp In ActivePage.Shapes
        ActiveWindow.Select vShp, visSelect   'This line not needed, but shows the current group being analyzed / edited
        If vShp.Shapes.Count > 1 Then          'Only grouped shapes have count greater than 1.  All others ignored
            For i = 1 To vShp.Shapes.Count      'Steps thru each member of the group.  Following lines do the editing.
                vShp.Shapes(i).CellsSRC(visSectionObject, visRowLock, visLockMoveX).FormulaU = "1"
                vShp.Shapes(i).CellsSRC(visSectionObject, visRowLock, visLockMoveY).FormulaU = "1"
            Next
        End If
    Next
    ActiveWindow.DeselectAll
End Sub
Visio 2019 Pro

wapperdude

Well just discovered and learned something new.  After you completed creating and arranging your group, you can open up the shapesheet for the group level shape, and then, there's this Group Properties section.  (This was the discovery!)  There is an entry in that section:  Don't move children.  Set that entry to True or "1", and you're done!!!

You could still automate this with VBA code.  The code for making the change is:


Sub LockSubs()
    Dim vShp As Visio.Shape
    Dim i as integer
   
    ActiveWindow.DeselectAll
   
    For Each vShp In ActivePage.Shapes
        ActiveWindow.Select vShp, visSelect   'This line not needed, but shows the current group being analyzed / edited
        If vShp.Shapes.Count > 1 Then          'Only grouped shapes have count greater than 1.  All others ignored
               vShp.CellsSRC(visSectionObject, visRowGroup, visGroupDontMoveChildren).FormulaU = "1"
        End If
    Next
    ActiveWindow.DeselectAll
End Sub
Visio 2019 Pro

smoore33

It will take me a while to digest and work with this, but I wanted to thank you so much for your helpfulness.
(And what the heck is the answer to "Why was 6 afraid of 7? Because 7 _ 9!:"?