Formula's for location

W

wdhough

Hi,

I have three boxes that appear to be in a group under one of the boxes in
the XML but also under the ShapeSheet window it has the following entries

PinX = Sheet.15!Width*0.15
PinY = Sheet.15!Height*0.5
LocPinX = Width*0.5
LocPinY = Height*0.5.

So what is the actual position on the page of my shape.

I think the Sheet.15 refers to another shape, but what part of it. The
rough answer for the pinx and piny of the shape should be something like PinX
= 2.125 and PinY = 6.375 ish. But doing lots of different calculations i
cant arrive at a number anyway near this.

Can anyone help in telling me how to interpret this "formula".

Thanks

Will
 
J

John

Will,

All 2D shapes have a Local pin x and y ('LocPinX' and 'LocPinY') that
defines where that particular shape's dimensions are drawn from. So, taking
a basic square shape (2 inches wide by 2 inches high) as an example:

"LocPinX = Width*0" ...... 2 inches times 0 = 0 (ie the left hand side of
the shape)
"LocPinX = Width*1" ...... 2 inches times 1 = 2 (ie the right hand side of
the shape)
"LocPinX = Width*0.5" ...... 2 inches times 0.5 = 1 (ie the middle of the
shape)

Now, the PinX (and PinY) refers to the shape's position on the page and this
could also be based on the position of another shape (and its LocalPinX/Y).
So in your example below, it depends on the LocPinX/Y of shape "Sheet.15".
Assuming (but have a look to check) that Sheet.15's LocPinX/Y is in the
centre of the shape then that's what we're measuring from.

So for your target shape, its X position is:
"PinX = Sheet.15!Width*0.15" ..... (PinX of Sheet.15) + (ThisShape'sWidth
times 0.15)

Similarly its Y position is:
"PinY = Sheet.15!Height*0.5" ..... (PinY of Sheet.15) + (ThisShape'sHeight
times 0.5)

Anyway, hope that helps. For a good overview, take a look at the link
below:
http://msdn.microsoft.com/library/d...trolling_Shape_Geometry_with_Formulas_607.asp

Best regards

John
 
W

wdhough

Hey John,

Thanks for your reply, found it very interesting. Still two more things i
need to ask though

you say that the PinX for this shape is = (PinX of Sheet15) + (This shape's
width times 0.15)

Well the width of this shape is defined as =Sheet15!Width*0.3
So i dont quite know how to evaluate that?

Also if your formula for working out the pinx of this shape is correct ie
"(PinX of Sheet15) + (This shape's width times 0.15)" then this would put it
to the right of sheet 15's pinx, which is not the case, forgive me if i have
that wrong.

Just an fyi the LocPinX and LocPinY for sheet 15 are
width*0.5 and height*0.5 respectively.

Also i'm not sure if i wrote this the first time and not sure if its
relevant but "this shape" is under a group with two others in the group, the
groups id is of course sheet 15, not sure if that makes a difference but just
in case its relevant

Thanks for your help john
 
J

John

Will,

Sorry, you're quite right I 'translated' the formula incorrectly.

I'll approach your questions in order below:

wdhough said:
Hey John,

Thanks for your reply, found it very interesting. Still two more things i
need to ask though

you say that the PinX for this shape is = (PinX of Sheet15) + (This
shape's
width times 0.15)


Sorry, my fault.....let me correct my original explanation

"So for your target shape, its X position is:
"PinX = Sheet.15!Width*0.15" ..... (The Width of Sheet.15 times 0.15)

Similarly its Y position is:
"PinY = Sheet.15!Height*0.5" ..... (The Height of Sheet.15 times 0.5)

This is very different and means that "this shape's" position is relative to
Sheet.15's size not position as I origanally said.

Well the width of this shape is defined as =Sheet15!Width*0.3
So i dont quite know how to evaluate that?

This means that "this shape's" width is roughly a third (0.3) of the width
of Shape.15
Also if your formula for working out the pinx of this shape is correct ie
"(PinX of Sheet15) + (This shape's width times 0.15)" then this would put
it
to the right of sheet 15's pinx, which is not the case, forgive me if i
have
that wrong.

Yes, again, my mistake. This may well be the case.
Just an fyi the LocPinX and LocPinY for sheet 15 are
width*0.5 and height*0.5 respectively.

Also i'm not sure if i wrote this the first time and not sure if its
relevant but "this shape" is under a group with two others in the group,
the
groups id is of course sheet 15, not sure if that makes a difference but
just
in case its relevant

Yes, it does make a difference. Just as a single shape's position is
relative to the page, a grouped shape's position is relative to its group
shape which, as you mention, is Sheet.15. So returning to the example, if
Sheet.15's width and height are 100mm then:

"PinX = Sheet.15!Width*0.15" = 15mm

....and in the case of the PinY:

"PinY = Sheet.15!Height*0.5" = 50mm

....and these are both relative to the group shape's origin.

One thing I don't think I made clear earlier is that a shape's coordinates
are relative to its origin, which is in starts at the bottom left hand
corner.

Anyway, apologies for the confusion. I was getting confused myself.

Best regards

John
 
J

John Marshall, MVP

The final step is to translate the PinX, PinY relative to the group shape
Sheet.15 to page coordinates. The following code shows
how XYToPage will do that
Public Sub XYTest()

Dim shpObj As Visio.Shape
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double

' Set this to the PinX and Piny
x1 = 0
y1 = 0

For Each shpObj In ActivePage.Shapes
shpObj.XYToPage x1, y1, x2, y2
Debug.Print x1, y1, x2, y2
Next shpObj

End Sub

--
John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 
W

wdhough

I still dont think thats correct.
Ok the width and height for sheet 15 are 2.5 and 0.375 respectively.

the pinx and piny for sheet 15 are 3.04 and 6.4107 respectively.

For "this shape" using your formula it would be (sheet15's widht *0.15) =
0.375.
This isnt right i can see that on the screen. The value we're looking for is
something is just below 2.25.
So i played around with some numbers and got this

(sheet15's pinx less its locpinx) + (sheet15's width * 0.15)
thats
3.04 - (2.5*0.5) + (2.5 *0.15) = 2.165 which looks about right
As mentioned before there are two other shapes in the group.
who's pinx formulas are "Sheet15!Width*0.5" and "Sheet15!Width*0.85"
using the above formula of :
(sheet15's pinx less its locpinx) + (sheet15's width * 0.15)
we get this
3.04 - (2.5*0.5) + (2.5*0.5) = 3.04 which looks right

and

3.04 - (2.5*0.5) + (2.5*0.85) = 3.915 which looks right.

It was your comment about "this shaped position being based on sheet 15's
dimensions" that gave me the idea. So since the pinx of sheet15 is measured
from the middle we need to used it based on its left most value which would
be its actual value less its locpinx, then you can do it....so do you reckon
thats right?


Will
 
W

wdhough

Thanks John but, i'm reading the xml file here, is the formula i just posted
correct then?

thanks

Will
 
J

John

Hi Will,

I think it is correct, because "this shape" PinX / Y are described in
relation to its parent's shape, which in this case is Sheet.15.

Let's step back a moment. If you think of a document as containing a number
of sheets of paper. Each page is a sheet of paper and each shape is sheet
of paper (albeit a smaller one).

Now, the "origin" of EVERY sheet of paper is (0,0), that is x and y for the
bottom left hand corner.

Each sheet of paper has a 'LocalPin' which is where you stick a nail to
locate it on another sheet of paper. In an average situation this is bang
in the middle of the sheet.

Each sheet of paper (apart from the "Page" sheet) has a PinX/Y which
describes where that sheet of paper is nailed TO in terms of the object that
it is being nailed to. Note, this may NOT necessarily be the "Page" sheet.

Groups - When you group two (or more) shapes together, you create another
shape, which marks the area of all of its 'sub-shapes'. Back to my paper
analogy - all of the sub-shapes locations (ie PinX/Y) are described in terms
of where they are 'nailed' to the group shape (and not the Page).

This means that if you want to find the Page coordinates of a sub-shape (ie
our "this shape") you need to translate this into Page coordinates as John
Marshall pointed out in an earlier post.

I hope that's clearer?

Best regards

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top