Protect LocPinX and LocPinY

Started by rezingg, February 13, 2020, 11:14:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rezingg

Is there a way to protect LocPinX and LocPinY of a shape, such that the user can't drag that point in the GUI? I have activated Developer mode and am aware of the "Protection" dialog, but the only way I can prevent the user from moving LocPinX/Y is by protecting the shape from rotation, but I have to allow rotation.
The issue is that LocPinX/Y is not only the center for rotation, but the point by which the shape is placed. I use a simple macro to push all my shapes onto a grid to clean up diagrams, but sometimes a user has by accident moved the LocPinX/Y handle (this happens easily when trying to move a shape and grabbing it near the center). In that case the shape is pushed off-grid, because LocPinX/Y may have been moved off-grid.


vojo

in the shapesheet

pinx = guard(<some function or value>)       ///locks for ever
piny = guard(<some function or value>)       //locks for eever

An alternative would be to put the fixed shape on a background page and use that background page with foreground page
This way, user can move any shape on foreground, but can not move any shape on the background page as seen by on foreground (you can edit the background page to move shapes or whatever)

Lastly, you could look at setatref functions (disclaimer I have not ever done this)

pinx = setatref(user.pinx,setatexpreeval(<some fcn that uses setatrefexpr() >)) + <reconstruct pinx using a different approach based on page measurements>

piny = similar

Similar approach to constrain a control point along a circle (see recent posts by me)


rezingg

Thanks!
guard() works like a charm. Visio still shows the "move LocPinX/Y" cursor when moving the mouse over it, but when dragging the whole shape is moved, not just LocPinX/Y.

rezingg

Now I have a lot of shapes in a stencil. Is there a simple macro I could use to add guard() for LocPinX/Y in all shapes in my stencil and the document stencil?

vojo

locpinx, locpiny is relative width/height.
pinx/piny is the anchor on the page (relative to the page)...all loc does is where you want to anchor the shape against pinx

locpinx locates the left bottom, right bottom, left top, right top, center to the pinx

as far as macro goes, somebody may have one or you could write one.

But, if you have to do this manually, I would suggest experimenting with ability to lock or unlock pinx and piny
(this would allow you to move shapes when you want thru explicit actions...then lock it down)
but its your choice

Obviously, you realize that if copy paste this shape, it will sit on top of original and wont be able to move it
this could be a user annoyance.

rezingg

vojo, I want the user to be able to move the shapes, and also to rotate them. But I want to use a macro to push the shapes back onto a grid. All shapes were designed on a 1/16" grid. And All shapes have their LocPinX/Y on that grid as well. The user can move the shapes off the grid, but I can run my macro that will move them back onto the grid. What is moved onto the grid is LocX/Y, which is pinned to the shape via LocPinX/Y. So, if a user had moved the LocPinX/Y off the 1/16 grid, then the shape itself will end up off-grid when I move LocX/Y to the 1/16 grid. I don't see a need for my users to move LocPinX/Y, therefore the simplest solution for me is to prevent that move, and everything is good. guard() does exactly that. The only problem for me is now how to add guard() to LocPinX/Y on all the shapes in my stencils and the document stencil (I have one large document, no need to go to multiple documents).
I'll search if I can find pointers how to iterate through masters in stencils and make the changes there.

vojo

I guess I don't understand what you want to do

all Locpinx/y does is "orbit" around pinx/y.   You can guard them if you want, but user today has to take explicit actions to change the orientation of locpinx/y.  Personally, never found a need to guard locpinx/y....but your choice, go for it.

as far as macro goes...others may have something or start here http://visio.mvps.org/VBA/default.html

rezingg

vojo,
when the user moves the center of rotation handle in the GUI, both LocPinX/Y and PinX/Y of the shape are moved, such that that the shape is not moved, but the anchor point at which the shape is attached to the shape is moved.
When I run my macro to push the PinX/Y of all shapes onto a grid, the shape itself will end up off-grid if the user has pushed the anchor point off-grid relative to the shape.

Thanks for your help, guard() really solved my problem!

I have now a macro that works for me. (Note that the first item in all my master shapes is a group):

Sub GuardLocPinXY()
    Debug.Print "GuardLocPinXY"
    Dim fo As String
    Dim shp As Visio.Shape
    Dim shps As Visio.Shapes
    Dim mst As Visio.Master
    Dim doc As Visio.Document
    Set doc = ThisDocument '...or some document, perhaps Visio.ActiveDocument
    For Each mst In doc.Masters
        Set shps = mst.Shapes
        Set shp = shps.Item(1) 'grab first shape, should be group
        If shp.Type = visTypeGroup Then
            ' make sure LocPinX/Y are guarded
            fo = shp.Cells("LocPinX").FormulaU
            If InStr(UCase(fo), "GUARD(") = 0 Then '// if no guard() add it
                shp.Cells("LocPinX").FormulaU = "Guard(" + fo + ")"
            End If
            fo = shp.Cells("LocPinY").FormulaU
            If InStr(UCase(fo), "GUARD(") = 0 Then '// if no guard() add it
                shp.Cells("LocPinY").FormulaU = "Guard(" + fo + ")"
            End If
        Else
            Debug.Print "Top shape of master shape '" + mst.Name + "' is not a group."
        End If
    Next mst
End Sub



Yacine

@Wapperdude, yes there is indeed a lot of stuff involved.
Yacine

wapperdude

@Yacine:  Some of my favorite things.  Might as well get a list going, eh?!?  😱
Visio 2019 Pro