Development

Tips & code for programming Visio & using the ShapeSheet

Maps & Geography

Maps & geography shapes & templates galore!

Network

Shapes & tools for Visio network diagrams.

News

Find out what’s new in the Visio world!

Shapes

Download useful & attractive Visio shapes. For free!

where can i buy windows 7 cheapest buy windows 7 upgrade from xp windows vista purchase price buy inventor 2010 pctools spyware doctor 5.5 buy windows 7 best price norton ghost 12 product key windows 7 price future shop windows xp price singapore windows 2008 web server download omnipage coupon buy windows 7 starter download adobe indesign cs3 for mac buy vista to windows 7 microsoft project 2003 download buy windows xp operating system windows 7 home premium cheap mathcad pricing photoshop buy mac discount autocad 2009 purchase microsoft money 2007 deluxe download photoshop mac autodesk maya 2009 price windows vista business download windows 7 price 64 bit purchase windows 7 ultimate full version buy windows 7 home premium key lightroom for apple purchase windows xp india adobe cs4 photoshop buy where to buy encarta 2009 purchase vista oem buy windows 7 tesco cheap adobe fireworks windows 7 price online best price corel draw 11 mac discount powerpoint buy microsoft office for mac canada buy microsoft project 2002 adobe production premium mac turbotax 2009 deluxe best price windows 7 ultimate 64 bit best price buy windows 7 amazon adobe flash pricing adobe dreamweaver sale purchase windows 7 ultimate buy quickbooks pro 2007 roxio copy & convert 3 buy download photoshop elements 6 steinberg nuendo price uniblue registrybooster 2009 download cheap photoshop programs adobe photoshop elements cheapest buy windows 7 future shop adobe presenter 7 download microsoft office 2003 sale buy quarkxpress 8 for mac purchase adobe cs3 design premium purchase after effects cs3 paperport professional 12 prices cakewalk download parallels desktop price buy microsoft windows 7 home premium cheap adobe after effects for mac how to purchase windows 7 online download microsoft streets and trips 2008 microsoft office 2003 cheapest buy windows 7 online singapore purchase autodesk 3ds max 2009 buy windows xp pro best price adobe flash cs3 buy uniblue registrybooster 2009 cheap windows 7 ultimate retail buy autodesk autocad buy microsoft office document imaging purchase microsoft office 2003 buy windows xp media centre edition discount microsoft windows 7 ultimate windows 7 price upgrade cheap adobe photoshop software burnaware professional price buy acronis true image 2010 windows 7 price change buy acrobat 7 where to buy adobe flash cs3 quicken 2010 price buy windows xp corporate buy office 2007 student product key windows 7 price hong kong buy windows 7 64 buy acrobat professional 9 symantec winfax pro 10.4 buy cheap windows 7 keys adobe photoshop cs4 buy buy microsoft visio 2007 turbotax deluxe 2009 download windows xp price in rupees buy lightroom software buy windows 7 buy windows 7 serial key steinberg nuendo 3 download download autodesk 3ds max 9 buy ms project online windows 7 price egypt windows 2008 enterprise download parallels mac download adobe lightroom sale cheap cubase 5 where to buy windows xp service pack 2 purchase windows vista download cheap windows 7 in singapore lowest price microsoft office purchase windows 7 license key where can i buy windows 7 starter edition buy i.r.i.s. readiris pro 11 cheap windows xp operating system buy office 2003 key where to buy windows xp cheap autocad mechanical 2009 download buy matlab software buy 3ds max 2010 student download dragon naturally speaking autocad inventor download get autocad 2010 buy adobe illustrator cs2 buy windows 7 mac windows xp price canada steinberg cubase sx3 download cheap windows 2003 enterprise download adobe illustrator cs3 can i buy windows xp online windows xp price in malaysia buy adobe cs4 suite best price adobe illustrator cs3 download font folio 11 acdsee pro license key cs3 production premium mac ms streets and trips 2008 download download adobe illustrator mac windows 7 price in india where can i buy cubase sx3 windows vista download iso roxio creator 2010 coupon code microsoft office price student windows 7 home premium 64 bit oem buy microsoft frontpage software buy windows xp 64 pro cheap windows 7 home premium full version buy burnaware professional cheap microsoft works 9 microsoft visio download adobe cs4 web premium oem download disk director cheap adobe creative suite cs4 microsoft money home and business download buy parallels desktop 5 for mac cheapest norton 360 3.0 lightroom price buy windows vista pro microsoft money buy online buy microsoft expression blend 3 buy windows 7 full version for students purchase lightroom 2 buy microsoft office ultimate pdf converter professional 6 promotional code buy adobe cs3 design premium buy indesign cs3 software buy windows vista ultimate upgrade acdsee photo editor download microsoft office 2003 professional cheap windows 7 for college students illustrator cs3 download download adobe indesign cs4 cyberlink powerdirector prices buy windows vista ultimate license buy access 2003 online windows 7 price guide mathcad price buy after effects cs4 mac cheap fl studio 8 xxl cheap photoshop elements 8 buy windows vista home premium oem buy wordperfect x3 buy windows 7 home premium 64 bit buy windows 7 brisbane buy windows 7 bangkok autodesk mudbox price purchase vista license cheap adobe premiere elements 8 download adobe creative suite 4 design premium best price microsoft excel 2003 buy microsoft project 2000 microsoft expression price discount photoshop elements 8 cheap maya software 3ds max sale buy windows 7 ebay windows 7 price 2010 deskshare videoeditmagic 4.3 price buy windows xp 2010 norton 360 price comparison buy windows xp used adobe contribute mac purchase windows 7 for mac buy windows vista home premium product key buy windows 2003 datacenter buy windows 7 professional cheap microsoft windows 7 ultimate buy sony vegas pro 8 purchase access 2007 final cut express 4 cost download microsoft visio 2007 buy onenote 2003 photoshop lightroom for mac symantec pcanywhere download windows 7 price pakistan buy premiere pro cs3 cheap windows 7 for students in australia web page maker 3 download buy windows xp home sp3 adobe photoshop best buy cheap windows 2008 enterprise buy windows 7 direct download download microsoft mappoint 2009 buy windows xp home download microsoft autoroute 2007 europe ashampoo burning studio download buy windows xp calgary archicad 13 download adobe cs4 design premium trial price photoshop elements 8 windows 7 home premium cheapest autodesk lustre pricing purchase archicad 13 acdsee pro 2 download windows 7 discount canada vmware workstation 7 download discount autodesk 3ds max 2009 buy autodesk inventor professional buy windows xp home full version buy windows 7 language pack buy microsoft office 07 buy microsoft excel 2007 download propellerhead reason 4 mappoint 2009 european buy access 2007 only buy frontpage 2003 purchase windows 7 ultimate online purchase microsoft windows vista buy dragon naturally speaking 10 oil price vista gadget pinnacle studio 14 best price cheap corel video studio pro x2 buy photoshop 7 for mac buy adobe cs3 design premium mac download ashampoo burning studio 9 cheap microsoft project 2007 dvd ripper platinum 5 buy adobe premiere pro cs4 download best price microsoft windows vista windows 7 discount for high school students purchase windows 7 professional (64 bit) compare price photoshop buy windows 7 philippines buy microsoft office powerpoint 2007 purchase windows xp sp3 buy photoshop elements 8 mcafee total protection 2009 download best buy autocad 2009 buy windows vista singapore purchase windows 7 now buy windows xp mumbai buy windows 7 ultimate 64 bit oem windows 7 price kenya ms works download adobe acrobat 9 oem buy windows 7 downloadable adobe cs4 web premium trial cheap windows 7 professional best price windows 7 home premium oem download adobe photoshop elements 6 navisworks manage price windows 7 price comparison buy guitar pro 5.2 download acronis true image 11 buy nero 8 ultra edition acdsee price download adobe robohelp 8 buy powerdirector 7 ultra imsi turbofloorplan home and landscape pro 12 buy buy microsoft expression studio 2 windows 7 discount for military buy windows 7 30 download pinnacle studio 12 ultimate adobe acrobat price comparison mappoint 2009 europe buy cheap avanquest mylogomaker professional 2 buy windows xp cheap microsoft office discount code buy windows 7 switzerland buy windows xp volume license buy norton 360 download cheap adobe photoshop cs3 download microsoft expression studio 3 buy office 2010 professional fl studio 8 xxl download buy microsoft office 2007 home and student cheap adobe cs4 design premium abbyy finereader 9.0 express edition where to buy streets and trips 2010 office 2007 price student buy roxio creator 2010 cheap adobe cs4 master collection mac buy windows xp ebay cheap indesign software buy corel photoimpact x3 download avanquest mylogomaker professional 2 cheap ashampoo burning studio 8 adobe captivate pricing autocad architecture oem buy microsoft office pro 2007 where can i buy powerpoint 2003 turbo tax cost buy windows 7 india online purchase windows 7 license online buy adobe flash cs4 buy windows vista ultimate product key buy cs4 mac buy adobe indesign cs4 best buy microsoft windows 7 ultimate cheap adobe dreamweaver cs4 mac cheap windows 7 canada roxio creator 2009 special edition microsoft office 2010 price in india windows 7 price canadian buy windows xp embedded download corel draw 12 adobe creative suite 4 production premium download buy adobe photoshop cs3 extended buy windows vista business 64 bit buy ms office 2003 pro best buy quicken 2010 buy microsoft office for mac cheap buy adobe after effects cs4 cheap norton 360 3.0 best price adobe cs4 master collection windows 7 price for teachers buy windows xp student purchase adobe acrobat 8 professional buy sql server guitar pro 5 mac download
Home » Development, ShapeSheet, Video

Punish Your Users with (not so) SmartShapes That Misbehave

Submitted by Visio Guy on June 14, 2008 – 4:37 pm | | 4686 views 5 Comments

Read Full Article You can learn a lot from bad examples.

Call it learning-from-our-mistakes, anti-patterns, or devilish fun, there’s a lot to be gained by looking at how-not-to-do-it.

Those of us over 30 might remember our first introduction to BASIC programming, taught to us by our friend Jeff, in the electronics corner at the local super market. While Mom was shopping, Jeff went over to the Commodore Vic 20 demo kiosk and typed the following lines:

10 PRINT "Chris is a turkey!"
20 GOTO 10

Utterly useless, except for the fact that it forever singed into our memory the ideas of branching and infinite loops…

Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey! Chris is a turkey!

Ha ha ha. Very funny, Jeff.

Well BASIC is ancient history, but we continue to get our feet wet by creating some form of “Hello World” in the latest-and-greatest programming language. Hopelessly impractical, Hello World nonetheless introduces us to the syntax and basic workings of a language.

Three Terrible Examples

So for those of you who’ve noticed Visio’s ShapeSheet, and are curious about SmartShape capabilities, this article is about having mischievous fun while learning how not to create SmartShapes.

From three example shapes, you’ll learn how to make Visio shapes do stupid things and behave very badly! And if you’re not careful, you might get practical ideas for your very-own, actually-useful SmartShapes.

If you are completely new to the ShapeSheet, I suggest first reading John Goldsmith’s excellent introduction to Visio development, the ShapeSheet, and automating Visio. The article is located here: Just for starters. This will make the rest of this article easy to understand.

For those of you who have dabbled a bit, the rest shouldn’t be too difficult.

Freak Out!

For all of our shapes, we are going to create a special ShapeSheet cell–a flag, so to speak–that indicates that it is time for the shape to behave badly.

We’ll call this the “Freak Out” flag, and we’ll implement by adding a User-defined cell called User.freakOut to each ShapeSheet of our misbehaving shapes. Generally (but not always) this cell will contain an expression that evaluates to True or False.

Other cells in the ShapeSheet can then reference this cell, in a way very similar to how Microsoft Excel works.

The choice of cells that respond to User.freakOut determines how our Not-so SmartShape behaves!

Adding User-defined Cells

User-defined cells are a great vehicle for storing parameters and calculations in your shapes that you don’t want your users to see. To add a user cell to a shape, do this:

  1. Select your shape
  2. Choose: Window > Show ShapeSheet
  3. Right-click and choose: Insert Section…
  4. Check the User-defined cells option and hit OK
  5. Give the first cell in the User-defined cells section a name by clicking in the left-most column where the red text is and typing a new name
  6. You can add more cells by right-clicking and choosing: Insert Row

That’s all there is to it!

Disappearing Shape

Ont to example #1. Our unsuspecting user decides to correct the text on the shape, and disregards the warning.

First, she selects the shape:

Sentence1

Then she enters text-edit mode by double-clicking the shape, or by pressing F2. Placing the cursor at the end of the sentence, she completes the final word:

Sentence2

As the word “sentence” is completed, something dramatic happens: BIFF!

Sentence3

And when she clicks away from the shape, thereby de-selecting it, all visible traces of the shape vanish into thin air: POW!

Sentence4

Fun, eh?

Let’s look at the anatomy. Our misbehave flag looks like this:

User.freakOut = NOT( ISERR( FIND( “sentence”, SHAPETEXT(TheText) ) ) )

Wow! There are four ShapeSheet functions nested within each other! Let’s break it down a little so we can understand what it all means.

SHAPETEXT(TheText) is the way that we get an actual string that represents the text of the shape. Using this, along with various string-handling ShapeSheet functions, we can analyze the shape’s text.

A lot of beginners make the initial mistake of trying to compare strings directly in the ShapeSheet with expressions such as:

IF( “bob”=”steve”, True, False ).

This doesn’t work, because Visio tries to understand “bob” and “steve” as numerical expressions or ShapeSheet formulas, and essentially evaluates both of them as zero. The proper way to make such a test is to use ShapeSheet text-handling formulas, like this:

IF( STRSAME( “bob”, “steve” ), True, False ).

FIND simply searches the shape’s text to see if “sentence” is to be found. Very similar to the InStr function found in many programming languages. If the sub-string isn’t found, then the FIND returns #VALUE, which represents a ShapeSheet error.

If “sentence” is found, then FIND returns the position at which the sub-string appears. In this example, 36 is returned when our user completes the shape’s text.

ISERR is able to detect errors such as #VALUE.

NOT, of course, finds the case when ISERR is false, thereby reversing the results of all that junk inside of ISERR.

To get the shape to disappear, we simply turn off the geometry section that defines the box, and hide the text. That requires two references to our Freak Out flag, in two different cells:

Geometry1.NoShow = User.freakOut

Miscellaneous.HideText = User.freakOut

NoShow and HideText expect boolean values, which User.freakOut is more than happy to supply.

Intermission

Since these DumbShapes are intended to suprise, frustrate and annoy, it is really best to see them Live!, in action.

So I’ve prepared a little video that shows all three examples in motion, as your victims will experience them. The video is narrated, so turn up your speakers and enjoy!

Frozen Shape

Our next user sucker comes along and sees this shape:

Frozen1

He also decides to ignore the warning and move this shape:

Frozen2

Not satisfied with the new position of the shape, he decides to move it again, only to find that it is now locked in place, and can’t be moved. How delightfully frustrating!

So how did we get this to work? Let’s look at our special User-defined cell. This one is a bit different:

User.freakOut = DEPENDSON( PinX, PinY ) + SETF( GetRef( LockMoveX ), 1 ) + SETF( GetRef( LockMoveY ), 1 )

In this case, other cells don’t react to User.freakOut. User.freakOut does the talking by pushing values into other cells!

The Pin represents the position of a shape on the page. Two ShapeSheet cells control this value: ShapeTransform.PinX and ShapeTransform.PinY.

DEPENDSON simply watches for cells within the parentheses to change. If they do, then the entire formula gets triggered for re-evaluation.

SETF is used to push values or formulas into other cells. This is kind of backwards to the way spreadsheets are supposed to work. You can get some really cool effects doing this, but if you get too tricky, you can also create quite a mess!

In this case, we are pushing the value 1 into the cells Protection.LockMoveX and Protection.LockMoveY. This keeps the shape from being moved (but not resized!)

GetRef does two things: it shields the formula from being evaluated by changes to LockMoveX or LockMoveY. After all, we only want the cell to evaluate when the shape is moved, i.e., when PinX or PinY is changed.

The second purpose for GetRef is to maintain links to named-cells that might change during the development process. For instance, I might have started out with a flag called User.f. Then later renamed it to User.flag.

GetRef( User.f ) will update to GetRef( user.flag ) when the change is made, thus freeing the developer from extra worry.

In older versions of Visio, GetRef didn’t exist, so target cells were enclosed in quotes: SETF( “User.f”, 1 ). Changes to named cells weren’t updated, because the quote marks hid them from the ShapeSheet engine, and lots of stuff got broken as a result.

Convenience and Sneakiness

Now, being a developer, of course I’ve left myself an out. If you double-click the shape, then the locked cells are reset to 0, so the shape can be moved. Again, SETF is employed to do this:

Events.EventDblClick = SETF( GetRef( LockMoveX ), 0 ) + SETF( GetRef( LockMoveY ), 0 )

Since we needed to reset two different cells, we just add two SETF expressions together. The result isn’t important in this case, just the pushing of values to the LockMoveX and LockMoveY cells.

And, we can again move our shape (once!) before it gets locked down again by our ShapeSheet shenanigans. Note also, that double-click won’t get you to text-edit mode. The expression in EventDblClick overrides and eliminates this behavior.

Dr. Jekyll & Mr. Hyde

Well, we sure hope you’re having fun! Our last example is a bit more complicated, and covers several topics, and should probably be a separate article. So if your boss is coming, bookmark this bit and come back later.

The concepts we’re going to need to understand to get Mr. Hyde to show his ugly mug include:

  • Referencing the Page’s ShapeSheet
  • Determining a shape’s ID
  • Inserting Text Fields
  • Referencing the group’s ShapeSheet from sub-shapes

Phew! Time to get up and stretch. See you in a few minutes…

In our last example, Visio Guy politely states his Pin Preference:

OnPageJekyll

Again, another disrespectful user comes along, disregards the warning, move Mr. Guy off of the page, and receives the punishment he sorely deserves:

OffPageHyde

So what’s the anatomy of this beast?

User.freakOut = OR( PinX<0, PinX>ThePage!PageWidth, PinY<0, PinY>ThePage!PageHeight )

Well, that looks like a lot, but it’s not really rocket science.

The OR function just says; “I am True if any of the conditions between my parentheses is true.”

And there are four conditions inside this OR function. They determine if the shape is off the page on any of the four sides:

  1. To the left: PinX < 0
  2. To the right: PinX > ThePage!PageWidth
  3. To the bottom: PinY < 0
  4. To the top: PinY > ThePage!PageHeight

Note the syntax for cross-sheet references. The ! is used to distinguish other “sheets”: ShapeSheets belonging to other shapes. In this case, we are referring to a special shape called ThePage, which–you guessed it–represents the actual page upon which we are drawing!

We can now tell if our shape is on or off of the page!

Smart Text

To control the text, we then created:

User.text = IF( User.freakOut, “I MEANT IT!”, “I prefer to be on the page.” )

and inserted it as a field in the word balloon. Since the word balloon is a sub-shape, we needed to do a little more work…

Referencing the Group

The whole shape is a group, containing several sub-shapes. In order to reference the top-level shape from a sub-shape, we need to know the ID of the top-level, group shape. We get this from the Format > Special dialog.

Now, in Visio 2007, this menu item isn’t on by default, so we need to turn on “Developer Mode” by going to: Tools > Options > Advanced tab and checking: Run in developer mode.

So let’s say that our group’s ID is 27, which we see right next to ID: label, at the top of the Special dialog.

Knowing the group’s ID, a sub-shape can refer to cells in the group’s ShapeSheet using the !-syntax we mentioned earlier. For instance, a sub-shape could be 1/2 the width of it’s parent with a formula like this:

Width = Sheet.27!Width*0.5

Inserting Text Fields

Armed with the ability to make cross-sheet references in our formulas, we set off to link the word balloon’s text to the group’s User.text cell.

So we sub-selected the word balloon and pressed F2 to enter text edit mode. Then, we chose: Insert > Field from the menu.

This is where we enter smart formulas for a shape’s text. From the Category list, we choose Custom Formula, and enter:

Custom Formula = Sheet.27!User.text

Our word balloon will now reflect the value of User.text in the group’s ShapeSheet.

Showing, Hiding and Coloring

Each of the horns has its visibility controlled by:

Geometry1.NoShow = NOT( Sheet.27!User.freakOut )

The eyebrows rotate and change color like this:

Shape Transform.Angle = GUARD( IF(Sheet.27!User.freakOut,-20 deg, 0 ) )

Fill Format.FillForegnd = GUARD( IF( Sheet.27!User.freakOut, RGB( 255, 0, 0 ), RGB( 0, 0, 0 ) ) )

And the eyes change color in a similar fashion.

Well, I hope you’ve found this article not only entertaining, but slightly educational. Now get out that copy of Visio sitting under your monitor and give some of these concepts a try!

Related Reading

If you’re interested in learning more about how to hide shapes and parts of shapes, be sure to check out: The Hidden World of Visio Shapes.

And by the way, you can find that snazzy word balloon shape in this appropriately-named article: Word Balloon Shape

Related Posts

  1. Center-sizing Smart Shapes
  2. SmartShape Tutorial: Fading Trees
  3. A Re-programmable Visio Multi-shape: The Configurable Stickman!
  4. How to Build Smart Frames and Bezels #2
  5. The Hidden World of Visio Shapes

5 Comments »

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.