Author Topic: retaining rotation inside nested groups  (Read 7342 times)

0 Members and 1 Guest are viewing this topic.

munnke

  • Newbie
  • *
  • Posts: 4
retaining rotation inside nested groups
« on: July 25, 2008, 01:24:13 PM »
I am trying to textboxes inside of a group to always be horrisontal relative to the page. The problem is that these groups can be nested inside variable numbers of other groups, and these other groups can be rotated. 3 textboxes move based off of a single control point, but 2 are offset vertically by .25 in, 1 above and 1 below. The shape is currently designed to not be rotated apart from its parent, and if it is, the PinX and PinY formulas cause it to no longer display properly.

I need these textboxes to always appear in the same orrientation relative to eachother and relative to the page, without having to modify the shape sheet information if the shape is grouped or ungrouped. The end users of this shape will not have extensive training in Visio or know how to use the shapesheet. I am droping these shapes into every group they are needed with a vb macro to update existing drawings, and they need to be resiliant to untrained modification.

I am restriced to using Visio 2002.

Sample code for the lower textbox, Sheet.2019 is the parrent group.
PinX
=GUARD(IF(Sheet.2019!FlipX=0,Sheet.2019!Controls.X4-SIN(Sheet.2019!Angle)*0.25,Sheet.2019!Controls.X4+SIN(Sheet.2019!Angle)*0.25))


PinY
=GUARD(IF(Sheet.2019!FlipY=0,Sheet.2019!Controls.Y4-COS(Sheet.2019!Angle)*0.25,Sheet.2019!Controls.Y4+COS(Sheet.2019!Angle)*0.25))

Angle
=IF(BITXOR(Sheet.2019!FlipX,Sheet.2019!FlipY),1,-1)*Sheet.2019!Angle

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3829
  • Ideas Visio-lized into solutions
Re: retaining rotation inside nested groups
« Reply #1 on: July 27, 2008, 09:41:20 PM »
This ought to be possible by initially setting up the shapesheets.  Text rotation is controlled in the Text Transform section.  Basically, you set the cell entry to be -Angle.  That causes it to rotate opposite direction of the shape.  However, since you have groupings, it will be the group angle that must be passed down into each shape in that group.  So, if shape1 and shape2 are grouped to form shape 3, then, the entries for both shapes 1 & 2 would be -Sheet.3!Angle.

This ought to work.
Visio 2019 Pro

munnke

  • Newbie
  • *
  • Posts: 4
Re: retaining rotation inside nested groups
« Reply #2 on: September 04, 2008, 03:01:51 PM »
unfortunately, setting -Angle does not work very well when trying to automate solutions. You need to know how many groups your object is in and then use -Angle for each.
For example, I have shapes 1 & 2 in 3, but then 3 could be in a 4, and 4 might even be in a 5

To fix the problem, I am using the AngletoPar command
ANGLETOPAR(0 deg.,ThePage!Width,Width)

unfortunately, this function doesn't seem to work correctly when FlipX is true on a parrent. to account for this, I am using:
=IF((parrent)!FlipX=0,(ANGLETOPAR(0 deg.,ThePage!Width,Width)),(ANGLETOPAR(180 deg.,ThePage!Width,Width)))

Users will have to manually rotate if parrents beyond the first are flipped in the X. I am forced to use visio 2002, and am currious if this is fixed in future versions.

I also changed the formulas used to calculate the offset from the control point for PinX and PinY and removed the sin and cos. I am using a a combination of LOCTOLOC and LOCTOPAR so that I conver my control point to the Page coordinate system, add my offset, and then convert back into the shape's parrent's coordinate system.

=GUARD(LOCTOPAR(PNT(PNTX(LOCTOLOC(PNT((parent)!Controls.X5,(parent)!Controls.Y5),(parent)!Width,ThePage!Width)),PNTY(LOCTOLOC(PNT((parent)!Controls.X5,(parent)!Controls.Y5),(parent)!Width,ThePage!Width))-0.25),ThePage!Width,Width))

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1718
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: retaining rotation inside nested groups
« Reply #3 on: September 04, 2008, 04:19:46 PM »
Interesting bug, munnke,

Would it be an option for you to protect your top-level groups from flipping? Ie:

FlipX = GUARD(0)
FlipY = GUARD(0)

??
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

munnke

  • Newbie
  • *
  • Posts: 4
Re: retaining rotation inside nested groups
« Reply #4 on: September 04, 2008, 04:29:43 PM »
I am using macros to drop these shapes into already existing drawings, and it is rare enough that I'm not worried about it. Changing the offset to use LocToPar allows me to rotate the shapes and not have to worry about screwing up the offset.
« Last Edit: September 04, 2008, 04:51:53 PM by Visio Guy »

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1718
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: retaining rotation inside nested groups
« Reply #5 on: September 04, 2008, 05:02:59 PM »
A few more observations:

The angle of a shape is actually "local" to it's container. Like PinX and PinY, Angle is relative to the parent's coordinate system. So getting a "local angle" is not quite right.

You might want to use AngleToLoc, where the source is ThePage and the destination is the parent of the shape. Using VBA, you can get at a parent's id via:

shp.ContainingShape.NameID

I played further with this, and the flip problem still seems to persist, though. I am using Visio 2007, so the bug is still there, or we're not getting the formula right.

Another tack my be to use the ParToLoc type functions to compute the local value of two points on the page: (0,0) and (1,0), which you could then use as a "vector at 0 deg on the page" and use an inverse trig function to get the proper angle. This might solve the flip problems. But it's getting late here, so I'm not going to try it myself :)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3829
  • Ideas Visio-lized into solutions
Re: retaining rotation inside nested groups
« Reply #6 on: September 05, 2008, 10:33:15 AM »
Well, since you all have done the hard part  ;), here's the fix to the angle rotation formula:

=IF(BITXOR(Sheet.7!FlipX,Sheet.7!FlipY),-ANGLETOPAR(180 deg+Angle,ThePage!Width,Width),-ANGLETOPAR(Angle,ThePage!Width,Width)). 

Sheet.7 is my "parent" group sheet.  The formula is placed in the TxtTransform section of the shapesheet for my bottom most shape, nested 2 deep.

Note, it might be a little more intuitive, to alter the formula slightly:

=IF(BITXOR(Sheet.7!FlipX,Sheet.7!FlipY),-ANGLETOPAR(180 deg+Angle,ThePage!Angle,Angle),-ANGLETOPAR(Angle,ThePage!Angle,Angle)).  It works the same either way.
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3829
  • Ideas Visio-lized into solutions
Re: retaining rotation inside nested groups
« Reply #7 on: September 05, 2008, 10:54:18 AM »
 ::)  Ah!  The previous formula was for text in a nested shape.  For nested, stand-alone text, it may be necessary to remove the minus signs in front of the angletopar functions.

I forgot to say, that the formula is entered into the TxtAngle cell, but, that should be obvious.

The formulas, as given, are literal.  Do not substitue a numeric value for the "angle".
Visio 2019 Pro