Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Visisthebest on February 20, 2022, 12:22:11 PM

Title: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: Visisthebest on February 20, 2022, 12:22:11 PM
Is there a shapesheet function that does what VBA's Shape.XYToPage does for grouped shapes, to get the coordinates on the page rather than within the group?

See: https://docs.microsoft.com/en-us/office/vba/api/visio.shape.xytopage
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: Paul Herber on February 20, 2022, 01:01:59 PM
The top-level shape of the group's PinX/Piny give you the shape's page coordinates.
Is that any use?
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: Visisthebest on February 20, 2022, 01:18:37 PM
Yes of course so simple can just refer to those values with subshape user row formula thank you Paul!
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: Visisthebest on February 20, 2022, 10:27:55 PM
Another use case Paul is to detect whether the user has grouped a shape (so I don't know the ID of the group shape that the shape has become a subshape of).

Would something like LOCTOPAR do what I need in this case, to get the X and Y values in page coordinates?

https://docs.microsoft.com/en-us/office/client-developer/visio/loctopar-function?redirectedfrom=MSDN

Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: wapperdude on February 21, 2022, 12:45:47 AM
I'm assuming that the page. coordinates for the sub are merely for reference info.  You might get that info for the sub using the loctopar fcn, using the page as the pseudo parent.  That way, no worries re parent shape ID.
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: wapperdude on February 21, 2022, 01:08:12 AM
Specifically, this formula works:  =LOTOLOC(PNT(LocPinX,LocPinY),Width,ThePage!PageWidth).  Simple Google of Shapesheet functions gets you to this formula.
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: Visisthebest on February 21, 2022, 09:38:01 AM
Thank you wapperdude this is a very useful function, I think I could create a 'detector' that detects if a user is grouping my special shapes:

1. Add to user row:  =LOTOLOC(PNT(LocPinX,LocPinY),Width,ThePage!PageWidth)
2. Compare values to shape's own cell, if they differ then fire QUEUEMARKEREVENT
3. Check whether shape has become part of a group of shapes, give user warning message and undo the group

I could listen for the event of a user grouping shapes as well of course, but then my sub/function will fire when any shape is grouped, now I get a notice only when specific shapes are fired.
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: Visisthebest on February 21, 2022, 06:41:40 PM
Is there a shapesheet function that allows me to compare points to check if they're equal.

If I try:
IF(PNT(PinX,PinY)=User.Row_2,"Shape is ungrouped","Shape is grouped")

and User.Row2 contains:
=LOCTOLOC(PNT(LocPinX,LocPinY),Width,ThePage!PageWidth)

I always get the answer true back, even though the points are not the same when the shape is grouped (if I compare to PNT(0,0) I still get true regardless of the shape's position).

Seems I need another shapesheet function to perform this comparison, hopefully there is one!
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: wapperdude on February 22, 2022, 01:52:39 AM
You may have to parse the point into its x- & y- values, and then compare x to x &  y to y.  Chexk PntX and PntY functions.
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: Visisthebest on February 22, 2022, 07:18:04 AM
Thank you Wapperdude that works well:

In User.Row_2:
=LOCTOLOC(PNT(LocPinX,LocPinY),Width,ThePage!PageWidth)

Then in User.IfTrueUserHasNotPutThisShapeInAGroup
=AND(PinX=PNTX(User.Row_2),PinY=PNTY(User.Row_2))

This formula will be TRUE is the shape is not in a group, FALSE if the user has grouped the shape into a new group.

-> the edge condition would be if the group starts exactly where the page starts, but I'll take that possibility for granted won't cause issues.

(the shape itself can be a group, but this is for checking if the user has put this (group) shape in another group).
Title: Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
Post by: wapperdude on February 22, 2022, 02:35:00 PM
That has to be the longest row name I've ever seen!   ;D. But, you'll always know why it's there.   ;)

Glad it's working for you.