Author Topic: A shapesheet function that does what Shape.XYToPage does for grouped shapes  (Read 806 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
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
Visio 2021 Professional

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3281
    • Paul Herber's website
The top-level shape of the group's PinX/Piny give you the shape's page coordinates.
Is that any use?
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
Yes of course so simple can just refer to those values with subshape user row formula thank you Paul!
Visio 2021 Professional

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
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

Visio 2021 Professional

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
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.
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Specifically, this formula works:  =LOTOLOC(PNT(LocPinX,LocPinY),Width,ThePage!PageWidth).  Simple Google of Shapesheet functions gets you to this formula.
Visio 2019 Pro

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
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.
Visio 2021 Professional

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
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!
« Last Edit: February 22, 2022, 02:14:32 AM by Visisthebest »
Visio 2021 Professional

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
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.
Visio 2019 Pro

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
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).
« Last Edit: February 22, 2022, 02:19:56 AM by Visisthebest »
Visio 2021 Professional

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: A shapesheet function that does what Shape.XYToPage does for grouped shapes
« Reply #10 on: February 22, 2022, 09:35:00 AM »
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.
Visio 2019 Pro