Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visisthebest on January 11, 2021, 03:06:17 PM

Title: Best way to get absolute position of subshape on Page
Post by: Visisthebest on January 11, 2021, 03:06:17 PM
For some user functionalities in VBA I worry that a user has grouped shapes together while my VBA subs/functions assume they are on the page (all shapes I use are already grouped shapes).

My subs/functions assume these shapes have a PinX/PinY relative to the page so if the user groups the shapes, and the PinX/PinY become relative to the group, things go haywire.

It would be great to be able to block grouping on certain shapes (already happy I can block ungrouping), but maybe even better to always read the absolute PinX and PinY (on the page) of my shape so I don't have to worry the user has grouped them.

What is the best way to do this? Thank you for your advice!
Title: Re: Best way to get absolute position of subshape on Page
Post by: Visisthebest on January 12, 2021, 05:43:54 AM
Solution I came up with now is to check the formula for PinX and PinY, if they are not just numbers (absolute position on the page) but contain a reference to another (the group) shape, then I inform the user the software first has to ungroup the shape group he's made before continuing.
Title: Re: Best way to get absolute position of subshape on Page
Post by: Nikolay on January 12, 2021, 07:22:16 AM
You can use shape.XYToPage (https://docs.microsoft.com/en-us/office/vba/api/visio.shape.xytopage) to convert local coordinates to page coordinates.
Title: Re: Best way to get absolute position of subshape on Page
Post by: Visisthebest on January 12, 2021, 07:43:47 AM
Thank you Nikolay I was completely unaware such a function is available!