• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Visio Guy

Smart graphics for visual people




  • Home
  • Hire Me
    • Hire Me
    • Résumé
  • Products
    • Products
    • Bubble Revision Shape
    • Layers to Pages Utility
    • Rack Unit Dimension Line
    • Radial Elements Tool with up to 100 Wedges
    • Text on a Circle Visio SmartShape
  • Index
    • Articles by Date
    • YouTube – VisioGuy
    • Download Information
    • Suggestion Box
    • Shop
    • Visio Art
    • Visio Links
    • – Visio Shapes & Stencils
    • – Visio Templates & Drawings
  • About
    • About
    • Donate
    • GitHub
    • jsFiddle
    • Reading List
    • Subscribe & Follow
      • – E-mail
      • – facebook
      • – Twitter
      • – RSS
    • Privacy Policy
  • Discussion Forum
You are here: Home / Development / ShapeSheet / Constraining Angle with the BOUND ShapeSheet Function

Constraining Angle with the BOUND ShapeSheet Function

December 14, 2006 By Visio Guy 1 Comment

Cori who writes the blog Elliptical… wrote this nice little piece on constraining a shape’s angle so that it can only be rotated in 90-degree increments. I thought I’d relay the information to you here, and explain a bit more about the BOUND ShapeSheet function.

Although you can use the keyboard shortcuts Ctrl+R and Ctrl+L to rotate shapes in 90-degree increments clockwise and counterclockwise, this does nothing to actually constrain the allowable values.

Enter the BOUND ShapeSheet function

Compass SouthThe shape at right is a compass dial shape that can only point to north, south, east or west. When you grab the shape’s green, lollipop rotation handle, it will snap nicely to one of these directions. The BOUND function makes this possible.

Even if a user tries to foil the constraint by typing an odd value into the Size & Position’s Angle field, the shape will still be rotated to the nearest 90-degree increment.

The magic is located in the shape’s Angle cell, located in the Shape Transform section of this shape’s ShapeSheet.

When you look at the Angle cell, you might be shocked. This is what you’ll see:

Angle = BOUND(0 deg, 0, 0, 0 deg, 0 deg, 0, 90 deg, 90 deg, 0, 180 deg, 180 deg, 0, 270 deg, 270 deg)

Anybody still there? It’s not so formidable if you break it down. Let’s add some line breaks to make it more digestible:

BOUND(0 deg,0,
0, 0 deg, 0 deg,
0, 90 deg, 90 deg,
0, 180 deg, 180 deg,
0, 270 deg, 270 deg)

You can see right away that there are four triplets of information that correspond to our four allowable angles: 0 deg, 90 deg, 180 deg and 270 deg. So the west-constraining triplet would be:

0, 180 deg, 180 deg

The second two arguments could be described as the from-value and the to-value. Since we are constraining to specific points, these values are the same for each compass direction. In this example, we have from 180 deg and to 180 deg, which means: west.

The 0 that you see at the beginning of each triplet is an ignore parameter. If you set this to 1, then the constraint will be turned off. You could put various IF conditions or true/false flags in each individual ignore parameter to make a seriously whacky shape! Or you could reference all of the ignore flags to, say a User.debug cell, which would allow you to turn off the constraints to perhaps make development of the shape easier.

You’ll notice that the BOUND function doesn’t get deleted when you rotate the shape, and that GUARD is not used to accomplish this. BOUND is part of a new class of functions, first introduced in Visio 2003 that allow better coexistence between parameter-input and user-interaction. When you rotate the shape, the angle to which you rotate will be stored in the very first argument. So if I rotate the shape to -75.9 deg, the function will display as follows:

BOUND(-75.9 deg., …

The rest of the function will then work with that value to decide which constraint to use. So the user-interface generated angle is written inside of the function, without blasting the entire formula away! This is a a really cool concept that enables a lot of new possibilities for your shapes. The tyranny of GUARD is over!

We’ve almost forgotten the second argument, just after the value place-holder. This argument specifies the constraint type. The type can be one of three values: 0 = inclusive, 1 = exclusive, 2 = disabled. In our compass example, we have used 0, for inclusive constraints. Exclusive means “places where the value can’t go”, which adds interesting possibilites, and Disabled allows you to turn off the whole BOUND function. This could also be cool for debugging a shape.

Smart Text

If you’re interested in how the N, S, E, W shows in the text, have a look at the User-defined Cells section in the ShapeSheet. There, you’ll see two cells:

User.directions = “E;N;W;S”

User.direction = INDEX( INT( ANG360(Angle) / 90 deg ), User.directions )

The first cell is just a list of text to display. The second figures out which of those elements to use. By dividing the 360-degree-normalized angle by 90 degrees, the INT-ing it, we get a value of 0, 1, 2 or 3. This value is used to index one of the elements in the directions list.

The User.direction cell is then linked to the shape’s text using the Insert > Field dialog. Some gyrations were also performed in the Text Transform section to keep the text right-side-up as the shape rotates. Notably:

TxtAngle = -Angle

This causes the text to anti-rotate relative to the shape. A more complete formula is TxtAngle = IF(BITXOR(FlipX, FlipY), 1, -1)*Angle. This calculate the proper anti-angle even when the shape flips. But we could write many articles on text behavior, and probably will, so I’ll leave that for another time.

Hopefully you’ll find the BOUND function as fun and interesting as I have. Here’s the Visio file for download:

Download “Visio Bounds Function Example Compass Shape”

s!Aj0wJuswNyXlhRuAjguwA32bwY0l – Downloaded 1886 times – 103.00 B

More Info

We talked about how BOUND doesn’t get overwritten by user-interface actions. Here’s some links to the MSDN Visio 2003 SDK Documentation for ShapeSheet functions that support this “don’t overwrite me” behavior:

  • BOUND
  • SETATREF
  • SETATREFEVAL
  • SETATREFEXPR
  • Tweet
  • More
  • Pocket
  • Share on Tumblr
  • Print
  • Email

Related posts:

  1. Resize Text With Metafiles!
  2. Text Resizing with ShapeSheet Formulas
  3. Center-sizing Smart Shapes
  4. How to Build Smart Frames and Bezels #1
  5. How to Build Smart Frames and Bezels #2

Filed Under: ShapeSheet Tagged With: Formulas, Functions, ShapeSheet, SmartShapes, Text

Previous Post: « SharePoint Planning Visio Diagrams
Next Post: Visio 2007 General Information #2 »

Reader Interactions

Comments

  1. Yacine says

    March 7, 2010 at 5:30 pm

    Hi Chris,
    grossartiger Artikel, ich habe aber trotzdem eine Frage 🙂
    How would you bind a control point to a set of points.
    To explain myself:
    The control point shall only snap to certain points of a sub-shape and
    I certainly can bind the x values and the y values to sets of values. But how do I define that this particuliar y value corresponds to this other x value?
    Trials with loc(pnt()) did not work.
    Any idea?

Leave a Reply Cancel reply

Primary Sidebar

Buy Text on a Circle Shape
Article — Video — Purchase

Categories

Buy my book!

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Tag Cloud

A/V Artistic Effects BPM Code Connectors Control Handles Countries Custom Patterns Custom Properties Data Graphics Data Linking Data Visualization David Edson David Parker Fill Format Formulas Functions Geometry Gradient Images Links Maps Multi-shapes Network Programming repeating shapes Resources Right-Click Actions Scale Shape Data ShapeSheet ShapeSheet Formulas ShapeSheet Functions SharePoint shiny SmartShapes Sport Sports Text Themes Tools Transparency User-defined Cells Visio 2007 Visio SmartShapes

Top Posts & Pages

  • - Visio Shapes & Stencils
  • - Visio Templates & Drawings
  • Bubble Revision Shapes
  • Visio Network Server Shape Icon Customization Tool
  • Sankey Diagram Shapes for Visio
  • Amazon AWS Visio Shapes
  • Dynamic Updating Org Charts in Visio!
  • Go 3D with Free Isometric Piping Shapes for Visio
  • Text to the Bottom of the Shape
  • Map of World

www.visguy.com - Visio Guy - since 2006

 

Loading Comments...