Visio Guy

Visio Discussions => Programming & Code => Topic started by: chrisoft on May 27, 2016, 07:20:28 AM

Title: get the position into group
Post by: chrisoft on May 27, 2016, 07:20:28 AM
Dear VisGuy,

I am looking for a long time how to get the position of a shape that is in a group.
If I use :

debug.print shape.cells("Pinx").result("mm")  => The result is not matching with the position of the shape into the page.

Many Thanks in advance for your help
Title: Re: get the position into group
Post by: Surrogate on May 27, 2016, 07:44:06 AM
chrisoft,
Dim sh As Shape
Set sh = ActiveWindow.Selection.PrimaryItem.Shapes(1)
Debug.Print sh.Cells("Pinx").Result("mm")

this code matching position into group, i.e. local coordinates
Title: Re: get the position into group
Post by: chrisoft on June 03, 2016, 08:00:48 AM
Dear Surrogate,

Many Thanks for your prompt reply and sorry for my delay

I tried to use it but still returning a mismatching position value from the page.

What I am using is the below

dim shp as shape
Dim subShp as shape

For Each shp In ActivePage.Shapes
    If shp.Type = 2 Then 'vistypegroup
        For Each subShp In shp.Shapes
            Debug.Print subShp.Cells("Pinx").result("mm")
        Next
    End If
Next

Thanks in advance for your help ;)
Title: Re: get the position into group
Post by: vojo on June 03, 2016, 01:58:50 PM
Somebody may need to tune me up, but doesn't pinx/piny of subshape is relative to group pinx/piny

Ie absolute pinx/piny of subshape is
       group pinx - group locpinx + subshape pinx = absolute pinx of shape on page
       group piny + - group locpiny + subshape piny = absolute piny of shape on page

Example of X
    Group pinx = 300mm
    Group locpinx = 150mm
    subshape pinx = 20mm
 
    so   300mm - 150mm + 20mm = 170mm    absolute pinx of subshape.

Again, guys tune me up if I am wrong

As a test to simplify....make the group locpinx/locpiny = 0mm  (width*0 / height*0)
The math should be more obvious for this (easier to match up to grid readings)
Title: Re: get the position into group
Post by: wapperdude on June 03, 2016, 05:52:50 PM
You're correct Vojo, the sub shape c coordinates are relative to  group, not to page.

As I recall, the loctopar() fcn, where the page is the parent, ought to work too.

Wapperdude

Edit Update:  value of PinX in terms of page coordinates =PNTX(LOCTOPAR(PNT(LocPinX,LocPinY),Width,ThePage!PageWidth))
                    value of PinY in terms of page coordinates =PNTY(LOCTOPAR(PNT(LocPinX,LocPinY),Width,ThePage!PageWidth))
Title: Re: get the position into group
Post by: wapperdude on June 04, 2016, 12:51:29 AM
Attached example to illustrate the various "positional" relationships.

Sub-shape positions are relative to the group shape that contains them.  The reference is the group shape origin:  (0,0), i.e., width*0, height*0.  The PinX and PinY locations are relative to the (0,0) as determined by the offset factor:  LocPinX and LocPinY.  For example, LocPinX = 0.5*width and LocPinY = 0.5*height, would place the PinX, PinY location at the center of the shape.  The values for PinX and PinY are taken from the shapes location relative to the parent, e.g., the page, or the group.

Wapperdude
Title: Re: get the position into group
Post by: vojo on June 05, 2016, 12:41:23 AM
yes  loctopar is helpful for this.  I forgot about that family of functions

Thx Wrapperdude
Title: Re: get the position into group
Post by: wapperdude on June 05, 2016, 01:06:17 AM
I think those functions are like a bad experience...something the subconscious tries to suppress.   :D
Title: Re: get the position into group
Post by: chrisoft on June 05, 2016, 07:51:56 PM
Dear Both,

Much thanks for your help on this topic.

I tried the both solution and work perfectly.

you make my daily job better with Visio  ;)