get the position into group

Started by chrisoft, May 27, 2016, 07:20:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

chrisoft

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

Surrogate

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

chrisoft

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 ;)

vojo

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)

wapperdude

#4
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))
Visio 2019 Pro

wapperdude

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
Visio 2019 Pro

vojo

yes  loctopar is helpful for this.  I forgot about that family of functions

Thx Wrapperdude

wapperdude

I think those functions are like a bad experience...something the subconscious tries to suppress.   :D
Visio 2019 Pro

chrisoft

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  ;)