Share:

" /> Visio Guy » The Hidden World of Visio Shapes
Home » Code, ShapeSheet

The Hidden World of Visio Shapes

Submitted by on September 5, 2006 – 8:30 pm | | 309577 views 72 Comments

So you’ve created beautiful graphics in Visio, and you know how to add phantasmal ShapeSheet smarts to your shapes, now its time for you to make it all disappear! I often get asked how to toggle the visibility of various elements of Visio drawings, and I usually offer up one of many solutions. But I don’t think that those many solutions have ever been cataloged in a single place. Until, of course, now…

The Traditional Way

Let’s start with the traditional method of hiding things — the method I personally use most often. This method uses cells that specifically control the visibility of various parts of the shape.
The ShapeSheet has a number of cells that turn components on and off, all of which are TRUE/FALSE cells:

  • NoFill
  • NoLine
  • NoShow
  • Miscellaneous.HideText

While NoFill and NoLine allow you to fine-tune the look of a geometry section, NoShow makes the whole component invisible. Of course, sometimes you may want to hide an entire shape, like when it is a sub-shape inside of a group. In this case, you have to set every single NoShow cell in each geometry section, because there is no cell that hides the entire shape.

If you need to hide the text of the shape, that is easily accomplished via the Miscellaneous section’s HideText cell. If you have lots of elements to show and hide, it’s good to centralize the control in a user-cell. Below, we can see a shape configured to hide all geometry and text, according to the value of User.isHidden.

User.isHidden Geometry ShapeSheet Cell

Formatting

Of course, if you need to hide an entire shape, it seems like it makes sense to just use formatting. Your natural inclination might be to use the color cells to hide our shape:

  • Fill.Format.FillForegnd
  • Fill Format.FillBkgnd
  • Fill Format.ShdwForegndTrans
  • Fill Format.ShdwBackgndTrans
  • Line Format.LineColor
  • Character.Char.Color

However, there isn’t really a clear color, so we might choose white (color 1) to match the paper. This might work for most scenarios, but feels like a bit of a hack. You’d get into trouble if you had a shape hidden in this way laying on top of a visible shape, because the white would cover up the other shape.

In thinking about a clear color, we realize that it’s not the color that’s clear, but the pattern that’s none! So let’s consider the pattern cells:

  • Fill Format.FillPattern = IF( User.isHidden, 0, 1 )
  • FillFormat.ShdwPattern
  • Fill Format.LinePattern

While 0 represents the no-pattern for line and fill, there’s no equivalent for text. So we’ll still need to use Miscellaneous.HideText to make our characters invisible.A shape that is 100% transparent certainly has a clear color, so this might be another strategy: make the shape completely see-through! These cells control transparency in a shape:

  • Fill Format.FillForegndTrans = IF( User.isHidden, 100%, 0 )
  • Fill Format.FillBkgrndTrans
  • Fill Format.ShdwForegndTrans
  • Fill Format.ShdwBackgndTrans
  • Line Format.LineColorTrans
  • Character.Char.ColorTrans

This is nice, in that it doesn’t change the color of the shape in any way. But it can affect just as many cells as The Traditional Way, unless you have a very large number of geometry sections. Plus, it requires that messy IF statement that is considerably more typing than = User.isHidden

Another danger with using formatting cells has to do with styles. Even if you protect your formulas with the GUARD() function, the application of styles will blow the formula away. If a user chooses individual formatting options, like color, or pattern from a toolbar or dialog, then GUARD() survives. But if the user applies a style, then GUARD() gets blasted.

Size

See-through was a nice idea, but how about: too small to see? We can hide entire shapes by simply making them 0 x 0! Yes, you can make them infinitesimally small!
The only caveat here is that the font-size won’t automatically shrink with the shape. If you don’t use the HideText cell, then you’ll end up with an ugly, very tall, single-character wide column of text floating above an invisible shape!

Text In Squished Visio Shapes

Note that this strategy will require formulas in the shape’s Width and Height cells. If you GUARD these cells to protect your formulas, then the user won’t be able to change the size of the shape. However, if you’re using Visio 2003, though, then this won’t be a problem. A new function, SETATREFEXPR, will let you have the best of both worlds

This is how you would set the width and height formulas:

  • Shape Transform.Width = SETATREFEXPR( 3in ) * NOT( User.isHidden )
  • Shape Transform.Height = SETATREFEXPR( 3in )*NOT(User.isHidden)

If User.isHidden is TRUE, or 1, then the expressions evaluate to zero, and the shape disappears. If FALSE, or 0, then the formula evaluates to the last size to which the shape was sized. This last-size-value is stored in the parentheses and is shown as 3in in this example. I know it looks a bit weird, but it works!

Crop

If you have a foreign object in a shape, such as a bitmap or a metafile, you can do an interesting technique that’s related to cropping. You can simply shift the image out of the viewing panel!

When you have a foreign object in Visio, the ShapeSheet will contain the section: Foreign Image Info. This controls the zoom of the image relative to its shape-container, and the degree to which it is panned. By default, an image exactly matches its containing shape, and we have four very boring formulas, as shown:

Foreign Image Info ShapeSheet Section

You can simply change either the X or Y offset cells to be “times one”, and that will completely shift the image out of view, giving you nothing to look at!

  • Foreign Image Info.ImageOffsetX = ImgWidth * User.isHidden
  • Foreign Image Info.ImgOffsetY = ImgHeight*0

ImgOffset and Cropping in Visio

Notice the black line on the shape. That’s actually geometry! By default a foreign image shape has one geometry section that forms a rectangle around the shape. You’ll want to delete that section or hide it as well.

Layers

You can turn off a whole class of shapes by simply assigning them to a layer, then turning off the visibility of that layer. You add a shape to a layer via the Format > Layer dialog, and you change layer properties via the View > Layer Properties dialog.

And you can even manipulate layer visibility via the ShapeSheet. Suppose we have three layers on a page: Bob, Steve and Connector. In the page’s ShapeSheet, the Layers section would look something like this:

Visio Layers ShapeSheet Section

We could add a right-mouse action to a shape, or to the page that would allow users to quickly

toggle the visibility of this layer. In our case, layer Steve is in the second row, so it’s (his?) visibility cell is called Layers.Visible[2]

Actions.ToggleSteve.Action =
SETF( GetRef( ThePage!Layers.Visible[2] ), NOT( ThePage!Layers.Visible[2] ) )

An action in the page’s ShapeSheet doesn’t need the ThePage! Prefix, so the formula would be simpler:

Actions.ToggleSteve.Action
= SETF( GetRef( Layers.Visible[2] ), NOT( Layers.Visible[2]) )

It’s worth pointing out that it might not be such a good idea to put this action on a shape that belongs to the “Steve” layer itself, because you won’t have anything to right-click on the first time you hide the layer!

Toggle Layers With Right-mouse Context Menu

But right-mouse actions on the page are cool. You can quickly right-click the page, and toggle the “Steve” layer, and our life’s goals instantly become fulfilled!

Handles

You can also show and hide elements of the user interface, i.e.: handles and highlight-boxes. The miscellaneous section has five cells that deal with UI:

Miscellaneous Visio ShapeSheet Section

  • Miscellaneous.NoObjHandles
  • Miscellaneous.NoCtlHandles
  • Miscellaneous.NoAlignBox
  • Miscellaneous.DynFeedback
  • Miscellaneous.NoLiveDynamics

Normally, when you resize a shape, you see what it looks like, as you are dragging. If your shape is especially complex, this can bog down, and be jerky and distracting. It’s a good idea to set NoLiveDynamics to TRUE for complex shapes. Then the user will just see a “rubber-band” outline of the shape’s width and height as a sizing handle is dragged.

DynFeedback seems to only apply the Dynamic Connector shape, and controls the complexity of the ghosting displayed by the connector as you drag an endpoint. This cell didn’t seem to really affect anything.

I believe it might be a leftover from older versions of the Dynamic Connector, and isn’t particularly interesting anymore.

You can have shapes that are visible, but don’t print by setting the cell:

  • Miscellaneous.NonPrinting

Individual Control Handles

NoCtlHandles will turn off all of your control handles, but if you want to hide individual control handles, there is another technique: just add 5 to either the .XCon or .YCon cells. These cells are seen in the ShapeSheet under the column names: “X Behavior” and “Y Behavior”, but for some reason, the cells have these funny “Con” names. They specify how the control responds when the shape is resized (e.g.: “stay relative to the left/bottom” or “reposition proportionally”)

A common application of this technique is used for control handles that control the location of the text block. If the shape has no text, then we don’t want to have a control handle dangling in space. So we check for no-text, and turn off the control handle if this is true.

The system of formulas looks something like this:

  • Text Transform.TxtPinX = Controls.Row_1
  • Text Transform.TxtPinY = Controls.Row_1.Y
  • Controls.Row_1 = 0 + 5 * StrSame( ShapeText (TheText ), “” )

So if StrSame() is TRUE, that means we have no text, and we also have 5 x 1, which will hide the control handle. You only have to do this in either the X or Y cell, not both. I put 0 + at the beginning to illustrate that the 5-part can be separate from whatever control handle behavior you choose.

Automation methods:

Of course, there are many objects that you can hide via automation as well. These are fully documented in the Developer Reference help that ships with Visio, or you can get even more information from the Visio SDK. I’ll at least point you in the right direction here by giving you a rundown of the properties that you can set, and the objects they affect.

Visible property:

  • Application object
  • InvisibleApp object
  • Menu object
  • MenuItem object
  • MenuSet object
  • Toolbar object
  • ToolbarItem object
  • Window object

Hidden property

  • Master object
  • Style object

You can also create an invisible instance of the Visio application with code such as this:

Visio.InvisibleApp visAppInvis = new Visio.InvisibleApp);

Well, that’s about it for now. Time for me to disappear!

72 Comments »

  • Avinash says:

    is there any function to convert “anything” -> anything .. without char(34)

    plezz help

  • Sam says:

    Hi,

    I am creating an org chart using the visio wizard which works fine, now I need to colour the shapes according to different Business Units there are 11 different colours as well as hashed boxes. How will be the best way to produce this. Can we set this up in the main template or add a forumual to the excel sheet I am using?

    Thanks

    Sam

  • Visio Guy says:

    Hi Sam,

    If you’re using Visio 2010 Pro or Premium, you can define a Color by Value Data Graphic that will color the shapes based on values stored in their Shape Data fields.

    If you’ve got a different version or edition of Visio, look for this older add-on:

    Add-ons > Maps and Floorplans > Color by Values…

  • vinayak says:

    Please try with below code to change of shape object in visio.

    ThisShape.CellsU(“Width”).ResultIU = MaxWidth
    ThisShape.CellsU(“Height”).ResultIU = MaxHeight

  • ScottM says:

    How would I switch off data graphics associated with a single shape?
    When I change the noFill property on the shapesheet the datagraphic remains.

  • Visio Guy says:

    Hi Scott,

    If you’re doing it programmatically, then you can set the shape’s data graphic property to null.

    Here’s an example in Visual Basic:

    Visio.ActiveWindow.Selection(1).DataGraphic = Nothing

    There’s no easy way to do it via the ShapeSheet. You would have to go through every sub-shape in the data graphic and set the GeometryN.NoShow and HideText cells.

    Data graphics are designed to be applied and removed from shapes with zero or minimal impact on the shape itself. That’s the beauty of them. Add them when they’re needed, then remove them when they’re not!

  • tyrael says:

    Hi,

    I want to create a button to change the visibility of my layers so i used your code “= SETF( GetRef( Layers.Visible[2] ), NOT( Layers.Visible[2]) )” in the case events : eventDlCliks of my shape but I obtain an error in the formula.

    I also try to add an action by Insert/Section/Action
    and add the code :
    Actions.ToggleSteve.Action = SETF( GetRef( Layers.Visible[2] ), NOT( Layers.Visible[2]) )
    but it didn’t work

    I use Visio Standart 2007

    Do you have any solution ?

    Thank you for the tips
    Tyrael

  • tyrael says:

    I found the problem.
    It was an error with my value in the GETREF, i needed ThePage! and I enter a wrong value for my layer name, I wanted to find it with its name so I put “office”, when I changed with the number it worked.
    Thanks for the tutorial
    Tyrael

  • Dazza says:

    Hi

    I want to toggle visibility of shapes based on a date property in them

    But I want to do this for all diagrams that I use these shapes on..

    is this possible?

    thanks
    Dazza

  • David says:

    I’m looking for the formula to “highlight a shape” when receiving a specific value from an external data source. More specifically, I’ve imported excel data, and I want to take a shape and assign it to a specific data name – when that data is = “1” (which means 100%), I want a yellow highlight (or something) around that shape. What is happening here is I’ve got a Visio flow that matches a Project flow – since I don’t see a direct link from Project to Visio, I’ve off loaded the Project data to Excel, then imported into Visio From excel. So now I have external data in Visio – and i want to link specific fields to specific shapes and then highlight the shape (or some other kind of change to the shape) based on the external data. These are all 2010 versions (Visio, Excel, etc.) Im thinking I use the “New Data Graphic” option, but just don’t quite know what formual I’d use. Any help would be great.

  • Sean says:

    Visio Guy,

    I need to have all layers of a visible within the master layer but have any of the layers that are larger than the master layer to be hidden outside of the master layer. Does this make sense? Can I do this?

  • Visio Guy says:

    Hi Sean,

    Not exactly sure what you mean by “a larger layer”.

    I wonder if the Super Mask Visio Clipping Shape would help?

  • Tim says:

    Hi,

    I have a process map that includes reference to two databases. I want to colour the process steps according to the system being used in that step, I also want to have the flexibility to toggle seeing this colour – in the same way that making a layer visible/invisible would. Therefore just applying a fill to each shape would not allow this – is there a way to have the shape on one layer and the fill for that shape effectively on another so that i can achieve this?

    Any help would be really appreciated…thanks.

  • beginner says:

    Hello,

    I am a beginner and start my first steps with Visio Master Shapes.

    For this I want to make a control for the positioning of the text from the shape. This I find out and it works very good. But the alignment of the text is “centre”. I like to have the alignment left. When I use the align button left in top of menu it is left, but the control use centre. How can I say, that the control align left?

    thanx for your answers
    Beginner

  • Visio Guy says:

    Hi Beginner,

    Not sure what you mean, when you say “Control”. Are you using the ShapeSheet to define control handles?

  • Vivian says:

    Hey! I know this is kinda off topic however I’d figured I’d ask.

    Wouild you be interested in trading links or maybe guest writing a blog post or vice-versa?
    My blog discusses a lot of the same topics as yours and I frel we could greattly benefit from each other.

    If you’re interested ferl frse to send me an e-mail.
    I look forward to hearing from you! Excellent blog by the way!

  • twitter.com says:

    That’s why auto insurance is more expensive for teenagers than adults.
    Having a reliable safety net helps you avoid these highly expensive situations, making it possible for you to handle any financial or legal issues.
    This way you can get funds from your insurance faster
    to repair your car and make it run again.

  • Stephania says:

    This info is invaluable. Where can I find out more?

    Feel free to surf to my blog post; microsoft points generator (Stephania)

  • Juan says:

    Hi,

    it is possible to change the arrow heads in the connectors based on the value of a data field? same as we can do with the color.

    Thanks

    Juan

  • Joelrider21 says:

    Hi Visio Guy,

    I´m having the following problem and I would like to know if you can help me?
    I´m using Visio 2003 in Windons XP SP3 in my company.
    I create a template for drawing PFD and P&ID for the company´s projects. Associated to this template a created several custom properties sets for each type of shapes that I´ve also create to use in our projects.
    I assign thoses custons properties sets to the master shapes in the stencils created.

    So, now starts the problem. When I´m drawing something, draging the shapes to the sheet, I also insert the values in the custom properties fields.
    But after saving and closing the drawing and re-open it, those values are lost, just disappear.

    Can you help me?

    Thanks you

  • Dr. Dave says:

    I’ll try to explain this but don’t know if I’ll succeed.

    Have been using Visio 2003 for many years (love it). When I create a complex continuous line, i.e. straight, turn 90 straight, turn 90 etc. When I come to the end of the line and find out it’s too long or one of the segments is too long or in the wrong place, I simply click on the line (whole line is selected) keep the pointer over the line and within seconds there appear little diamonds at the various junctions. I can then grab these junctions in the middle or the end and move them anywhere I desire to straighten, extend, shorten, or move the line. The same thing happens when I create a freeform line and wish to modify it’s path. Viso 2010 will not do this. I’ve tried Ctrl and Alt with it but nothing works. This is a huge loss to my tools and causes me to do many redraws because I can’t edit the line. Many thanks, Dr. Dave.

  • Hi, I think your blog might be having browser compatibility issues.
    When I look at your blog site in Chrome, it looks fine but when opening in Internet
    Explorer, it has some overlapping. I just wanted
    to give you a quick heads up! Other then that, wonderful blog!

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.

*