Author Topic: Rotate a group of Shapes  (Read 5812 times)

0 Members and 1 Guest are viewing this topic.

mmulvenna

  • Full Member
  • ***
  • Posts: 91
Rotate a group of Shapes
« on: May 08, 2008, 09:23:50 AM »
I have a group of shapes that I have formulas for PINX and PINY. When i size or move the group my formulas work just fine.
When I rotate the group however, some of the formulas do not work.
Is there a way to calculate a new x and y coordinates based on the original coordinates using a formula for the angle of rotation?

Thanks
Mike

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1716
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Rotate a group of Shapes
« Reply #1 on: May 08, 2008, 01:06:05 PM »
Hi Mike,

What kind of formulas? Maybe post a few here so we can help.

But 'til then, I'll take a whack...

A typical formula to get a sub-shape to remain level when the group is rotated looks like this:

     Angle = -Sheet.5!Angle

where "Sheet.5" is the group.

More advanced, to handle horizontal and vertical flips of the group looks like this:

     Angle = IF( BITXOR( Sheet.5!FlipX, Sheet.5!FlipY ), Angle, -Angle )

Its not really obvious why, but it works, even when the group gets flipped!

Other functions related to transforming one shape's coordinates to another, which can be useful for shapes inside of groups include:

  • ANGLETOLOC
  • ANGLETOPAR
  • LOCTOLOC
  • LOCTOPAR
  • PAR
  • PNT

You can read more about these functions in the Developer Help or in the really nice help file that ships with the Visio 2007 SDK
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

mmulvenna

  • Full Member
  • ***
  • Posts: 91
Re: Rotate a group of Shapes
« Reply #2 on: May 08, 2008, 01:16:29 PM »
Thanks for the reply.
I do want all the shapes to rotate.
Here is a formula in the pinx cell of a shape.
=GUARD(Sheet.1!PinX-Sheet.1!LocPinX+LocPinX+Sheet.1!Width)

Also this one in the piny cell
=GUARD(Sheet.1!PinY+Sheet.1!LocPinY+LocPinY-(Height*2))

This works great when the selected group of shapes is moved or resized but does not correctly calculate when it is rotated.

The values appear to be off by some calculation of the angle.
« Last Edit: May 08, 2008, 03:20:26 PM by mmulvenna »

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1716
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Rotate a group of Shapes
« Reply #3 on: May 22, 2008, 01:16:12 PM »
Do you have a formula in the Angle cells as well? You won't get any rotation from PinX/PinY :)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

mmulvenna

  • Full Member
  • ***
  • Posts: 91
Re: Rotate a group of Shapes
« Reply #4 on: May 22, 2008, 07:21:49 PM »
I selected all the shapes and then grouped them. This automatically fixed most of the rotation issues because of group inheritance.

After the group is  rotated and I insert shapes and then add them to the group thru the code in the CALLTHIS function, I had to set the angle of the inserted shape to =guard(0) and the rotation using group handles work just fine. Also the flip functions from the menu work fine on the group.

Hope that makes sense ???

Thanks
Mike