Discussion:
How do I reference objects' positions in a Shapesheet?
(too old to reply)
Chelmite
2009-03-31 17:43:02 UTC
Permalink
I'm trying to build some "smart" shapes that will scale properly when the
shape is stretched.

I've drawn one object (Shape.5), an outline of a square.
It has four connection points.
Each connection point is specified with a formula such as the following to
calculate the midpoint.
Connections.C.X=(Geometry1.X1+Geometry1.X2)/2
Connections.C.Y=(Geometry1.Y1+Geometry1.Y2)/2

Another object is some text that's supposed to be aligned with a connection
point.
Its cells look like:
Width=GUARD(TEXTWIDTH(TheText))
Height=GUARD(TEXTHEIGHT(TheText,Width))
PinX=Sheet.5!PinX-Sheet.5!LocPinX+Sheet.5!Connections.C.X
PinY=Sheet.5!PinY-Sheet.5!LocPinY+Sheet.5!Connections.C.Y
LocPinX=Width*0.5
LocPinY=Height*0

So far, this is dandy. These two objects are inside a Master Shape on a
stencil.
When I make an instance of the shape, I can scale as I'd like.
However, the pieces of the cell can be selected and modified.

If, inside the Master shape, I create a group with the square and the text,
as soon as I group the two objects, the text moves down close to the origin
of the page instead of staying linked to the connection point of the square
inside the group.

What's the correct formula for tying an object to a point on another object.

Thanks for your help
P.S.
I'm using Visio 2003 on Windows XP, SP3.
Chris Roth [Visio MVP]
2009-04-01 10:43:25 UTC
Permalink
Hi Chelmite,

A couple of notes to get you going:

1. It's best to group shapes inside of a master, since Visio will group
them anyway when you drop them. You save the performance hit by
pre-grouping.
2. The location of Connections.N.X/Y is *local* to the shape that
contains the connection point. If you want to reference the location
from a separate shape, you need to transform that location to the parent
of the shape. In your case, both shapes should probably have the same
parent (the group), so something like this:

PinX = PAR(PNT(Sheet.5!Connections.A.X, Sheet.5!Connections.A.Y)) + Width/2

PinY = PAR(PNT(Sheet.5!Connections.A.X, Sheet.5!Connections.A.Y)) + Height/2

Notice that the PAR(PNT(... stuff is the same for both formulas. That is
because a PNT holds x and y data, and PinX and PinY know how to grab
just the part that they want. If it doesn't work quit right, you can
explicitly specify which part of the PNT to grab like this:


PinX = PNTX(PAR(PNT(Sheet.5!Connections.A.X, Sheet.5!Connections.A.Y)))
+ Width/2

PinY = PNTY(PAR(PNT(Sheet.5!Connections.A.X, Sheet.5!Connections.A.Y)))
+ Height/2

I know it looks a bit complicated and cryptic, but maybe this will get
you a bit further along.
--
Hope this helps,

Chris Roth
Visio MVP


Visio Guy: Smart Graphics for Visual People

Articles: http://www.visguy.com
Shapes: http://www.visguy.com/shapes
Dev: http://www.visguy.com/category/development/
Forum: http://www.viguy.com/vgforum
Post by Chelmite
I'm trying to build some "smart" shapes that will scale properly when the
shape is stretched.
I've drawn one object (Shape.5), an outline of a square.
It has four connection points.
Each connection point is specified with a formula such as the following to
calculate the midpoint.
Connections.C.X=(Geometry1.X1+Geometry1.X2)/2
Connections.C.Y=(Geometry1.Y1+Geometry1.Y2)/2
Another object is some text that's supposed to be aligned with a connection
point.
Width=GUARD(TEXTWIDTH(TheText))
Height=GUARD(TEXTHEIGHT(TheText,Width))
PinX=Sheet.5!PinX-Sheet.5!LocPinX+Sheet.5!Connections.C.X
PinY=Sheet.5!PinY-Sheet.5!LocPinY+Sheet.5!Connections.C.Y
LocPinX=Width*0.5
LocPinY=Height*0
So far, this is dandy. These two objects are inside a Master Shape on a
stencil.
When I make an instance of the shape, I can scale as I'd like.
However, the pieces of the cell can be selected and modified.
If, inside the Master shape, I create a group with the square and the text,
as soon as I group the two objects, the text moves down close to the origin
of the page instead of staying linked to the connection point of the square
inside the group.
What's the correct formula for tying an object to a point on another object.
Thanks for your help
P.S.
I'm using Visio 2003 on Windows XP, SP3.
Loading...