microsoft visio 2010 developer trainingmicrosoft visio 2010 developer training© 2010 microsoft ......

263
Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals Microsoft Visio 2010 Developer Training © 2010 Microsoft Corporation. All rights reserved. Volume 1: Shapes and ShapeSheet Fundamentals 1

Upload: duongthuan

Post on 30-Jan-2018

231 views

Category:

Documents


5 download

TRANSCRIPT

Microsoft Visio 2010 Developer Training

Microsoft Visio 2010 Developer Training

Volume 1: Shapes and ShapeSheet Fundamentals

DISCLAIMER

2010 Microsoft Corporation. All rights reserved.

Microsoft, Internet Explorer, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

The contents of this package are for informational and training purposes only and are provided "as is" without warranty of any kind, whether express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, and non-infringement.

No part of the text or software included in this training package may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission from Microsoft. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

To obtain authorization for uses other than those specified above, please visit the Microsoft Copyright Permissions Web page at http://www.microsoft.com/about/legal/permissions

This content is proprietary and confidential, and is intended only for users described in the content provided in this document. This content and information is provided to you under a Non-Disclosure Agreement and cannot be distributed. Copying, disclosing all or any portion of the content and/or information included in this document is strictly prohibited.

Table of ContentsTable of Contents3Visio Platform Introduction8Overview9In a Good Visio Solution12Visio Development Platform Architecture13Contents of a Typical Visio Solution15Stencils16Creating Masters17Editing Master Properties18Master Shortcuts20Instancing Masters22Inheritance vs. Local Formatting24Identifying Local Overrides26Visio File Extensions28XML for Visio30Templates32Creating a Template33Add-Ons and Macros34The Drawing Explorer36Review: Visio Platform Introduction38Shapes and ShapeSheet Fundamentals40Overview41Types of Visio Shapes42Visio Shapes as Parametric Objects45Visio ShapeSheet Environment47Review: Shapes and ShapeSheet Fundamentals49Defining Parametric Behavior51ShapeSheet Overview52Making a Smart Arrow54Making a Smart Arrow (Continued)55Controlling Geometry with Formulas56The Shape Transform Section58The Geometry Section60Coordinates in Visio61Parent Coordinates62The Pin Secures the Shape to the Page63Lab 1.1: Create a Directed Graph Shape65Referring to Other Shapes66Scope of Intershape References68Groups69Controlling Resize Behavior in Groups70Controlling Group Behavior72Controlling Group Behavior (Continued)74Shape Operations76Creating a Multishape78Lab 1.2: Multishapes and Actions80Review: Defining Parametric Behavior81Defining Text Behavior83Overview84Text Tools85Text Position88Controlling Text Position in the ShapeSheet90Text Rotation92Default Text Behavior93Level Text94Gravity Text95Text Fields96Text Field Custom Formulas98Resize Shapes with Formulas100Text Resizing Behavior102Multiple Text Blocks104Lab 1.3: Controlling Text Blocks106Review: Defining Text Behavior107Defining Page Environment109Overview110Page Setup Dialog111Page's ShapeSheet is known as the PageSheet112Working with the Page's ShapeSheet114Background Pages116Pages Can Share Background Pages117Using Background Pages118Lab 1.4 Define a Background Page119Assigning Shapes to Layers120Defining Layers122Review: Defining Page Environment124Defining Shape Interaction Behavior126Overview127Control Handles129Control Handle Uses130Defining a Control Handle131ShapeSheet Functions133Preventing Changes to Shapes135The GUARD Function136The Protection Section138Named Connection Points140Lab 1.5: Create a Word Balloon142Putting Actions on Shortcut Menus143Adding Smart Tags to Shapes146Making Shapes Respond to Events149Functions for Event Formulas151Hyperlinks153Lab 1.6: Shape Data and Hyperlinks155Review: Defining Shape Interaction Behavior156Adding Data to Shapes158Overview159User-defined Cells161Adding Shape Data to Shapes163Defining Shape Data165Filling in Shape Data168Shape Data Sets169Using Shape Data in reports171Data1, Data2, Data3174Scratch Section176Lab 1.7: Controlling a Shape using Shape Data177Review: Adding Data to Shapes179Special types of shapes180Structured Diagrams181Containers183Container Shape Details183Creating a visual style185Creating a heading sub-shape187Controlling container membership187Showing custom shapes in the Insert Container gallery188Using automation to get information about containers188Dropping containers with automation191List Shape Details195Specifying a shape to insert into lists196Controlling list membership196Callout Shapes200Using automation with Callouts203Summary for Special types of shapes206

Visio Platform Introduction

Overview

Before beginning to build solutions with Visio, you should first understand the components that make up a solution. On the surface there is the drawing environment that contains the drawing page, the stencils of master shapes, the templates, and the add-ons used to create the drawing. However, Visio drawings are much more than the lines and arcs that form the picture; they can be rich with information that describes the picture in detail. The drawing and the information that describes the drawing are referred to as a model.

Visio uses a robust inheritance model to keep the drawing compact. Shapes on the drawing page inherit from the Master in the local Document Stencil. Thus changes made to the master in the Document Stencil will affect all shapes that inherit from it.

The Drawing Explorer can be used to display a hierarchical view of your document. You can use the Drawing Explorer in Visio to view information about Templates, Stencils or Drawings.

Adding master shortcuts to your solution provides the flexibility of altering shape properties when an instance of the shape is created.

Objectives

Control how a Master is displayed by controlling Master shape properties. These properties help the user understand how a master can be used.

See how and why shapes inherit data from masters.

Create Visio templates.

Explore the components of the Visio drawing environment.

The following demonstration shows how a Visio drawing (a network diagram) can have additional information stored with the drawing and how this information can be used to generate useful reports.

Try it! Overview

1. Enable Macros by choosing the File > Options. This displays the Visio Options dialog. Choose Trust Center Settings to display the Trust Center dialog. Choose Macro Settings and then Enable all macros.

2. Open \Demos\Vol1\S1 Visio Platform Introduction\Network demo\Network Diagram.vsd.

3. Run the Create Purchase Order add-on by clicking on the page with the right mouse button. This add-on reads shape data information from the shapes in the drawing and displays this information in an Excel spreadsheet.

Following the demonstration you will compare the process of creating a drawing using traditional drafting techniques to designing a model using objects and Visio. You will also learn about the components of a typical Visio solution including master shapes, stencils, templates, and add-ons.

Try it! The Kitchen Sink Model

Draw a simple kitchen counter and cabinet layout two ways:

1. Open \Demos\Vol1\S1 Visio Platform Introduction\Sink Unfinished.vsd Try to reproduce the drawing using the Rectangle and Circle tools. Keep a count of the number of operations it takes to produce the solution using drawing primitives.

2. Using the open stencils, draw the kitchen cabinet with Base 2 (size to 48) and Sink 1. Keep a count of the number of operations it takes to produce the solution using objects.

Note:

It is easier to draw with graphic objects (pre drawn shapes) that than it is to use the drawing tools.

3. Go to the Kitchen Plan page of the drawing. Right-click on the page and run the macro called Generate Cabinet List. Like the network diagram example earlier, this add-on extracts shape data information from the drawing and writes it into a spreadsheet. There are additional right click menu items on the page for changing the cabinet finish and getting the total cost of the project. These are good examples of using Visio shapes with shape data to model a real world usage of designing a kitchen cabinet solution.

Note:

When you design with objects, you can generate usable information from the drawing. The drawing then becomes a model.

Models vs. Drawings

A model is constructed to help solve a problem. A drawing is usually just a partial view of a model. For example, in the case of business process analysis, the analysis may require that you know the cost per transaction of each process.

In a kitchen layout, the 2-D location of the cabinets specified in the plan view does not provide enough information to install the cabinets and counters. You also need to know the model numbers, colors, materials, heights, and so on. You can add this data to a Visio drawing so that the complete model is stored in the drawing.

If you have many drawings that have to be consistent, part of the model can reside in a single shared database (like a database of process inputs and outputs).

You can also combine information from a drawing (such as location and unique identifiers) with data stored elsewhere (such as a price list) to generate a complete model that can be used to generate parts lists and cost estimates.

Once a model is constructed:

Other graphical views can be constructed automatically using an add-on.

Analysis and reporting can be done automatically.

In a Good Visio Solution

Many objects in Visio correspond to objects in the real world. Ideally, they take on characteristics similar to their real-world counterparts. Consider the kitchen cabinet in the previous example. You set the cabinets width by setting a shape data value. These shape data values are in 3-inch increments, which is typical of cabinets purchased in the United States. By controlling the cabinets width in this manner, the user is prevented from inadvertently setting a value to a non-standard value. However, the shape does allow for non-standard values to be set. Thus you can override the default behavior for the object just as you can order a non-standard width for cabinets when you go to the cabinet supply store.

A good Visio solution ensures that a proper model is maintained. Again, going back to the kitchen example, when the cabinet objects are added to the drawing the user is prompted for information concerning cabinet style, color, manufacturer, and so on. This ensures that the data needed to generate the Bill of Materials is captured as part of the drawing data.

Visio Development Platform Architecture

Visio can be used to do much more than just create drawings. It provides a platform for creating solutions that integrate graphics with data in other forms, such as databases, spreadsheets, and word processors.

Lets look at the components of the platform architecture. At the core is the Visio graphics engine. The engine controls the environment: file management, user interface, graphics display, and so on.

A Visio drawing is typically constructed by using the drag-and-drop technique to add shapes to a drawing. These shapes are then positioned, resized, and connected to other shapes to create a finished drawing. Stencils are predefined collections of shape masters. By defining these master shape objects, the user can create very complex drawing documents without having to draw anything by hand.

Templates provide a starting point for a new drawing. A template can contain pre-drawn elements such as title boxes, logos, and frames. Templates can also pre-define scale, drawing size, paper size, and many other characteristics of the environment. Templates also define which stencil files are to be opened with the new drawing.

There are several solutions in Visio that have their own custom data import and export such as the Organization Chart and Timeline solutions. Visios Data Linking feature enables integration of external data with Visio drawings without requiring any custom software development.

Visio provides a type library that exposes all aspects of the Visio environment, including the drawing document, the shapes that make up the drawing, the windows, menus, pages, events, etc. This interface enables the basic Visio environment to be enhanced by adding components that do such tasks as automating drawing creation, analyzing drawing components, or integrating external data and other applications with a drawing.

These program enhancements can be created in the same development environments that you already use to create Office System applications.

Macros are procedures written in VBA code.

A .vsl file (Visio library file) is a standard Microsoft Windows DLL with a prescribed Visio entry point.

An .exe file is a stand-alone executable program.

A VSTO (Visual Studio Tools for Office) add-in for Visio is written in a .NET language and uses the .NET Framework Common Language Runtime to expose Visios automation interface.

A COM add-in is a COM object that implements the IDTExtensibility2 interface.

Note:

Visio solutions can also be implemented as an embeddable Visio component. You can use the Microsoft Office Visio Drawing Control in your application and get the full functionality of the Visio application through the Visio object model.

Contents of a Typical Visio Solution

The contents of a typical Visio solution contain a number of elements that make it well rounded and complete.

Stencils of master shapes give you the power to create your own custom shapes, and give users ease and flexibility in using them.

Templates are the best way to package a drawing solution, making it easier to distribute to users.

A typical custom Visio solution will also have custom code running behind the scenes that is manipulating the Visio object model. Custom solutions can take many forms and can be created using the Visio Drawing Control, XML, the .NET framework, COM add-ins, and Visual Basic for Applications.

Help files are an important component in a complete solution. Giving your users access to more information when they need it makes your solution more complete and user friendly.

As a developer, it is important to keep good documentation of your solution and what it provides for your users. This documentation is a solid foundation for writing pertinent help files and is a good starting point for compiling important training material.

Stencils

A shape on a stencil is called a master. A stencil serves as a container for holding related masters. A stencil can be standalone or local. A standalone stencil exists independently as a file with the extension .VSS. You create a standalone stencil by choosing from the Shapes window More Shapes > New Stencil. This will open a blank stencil that you can add your own master shapes to.

Normally, an existing stencil is opened as read-only. If you are modifying a stencil, make sure it is opened as Original or as a Copy (writeable). You can also make a read-only stencil writeable using the Edit command on the right-click menu on that stencil's title bar. Note that the Document Stencil can always be edited.

There is one local stencil that is always associated with the drawing called the Document Stencil. When you drag a master from a standalone stencil onto the drawing page, Visio copies the master to the Document Stencil, and then creates an instance of the master on the drawing page. Thus the Document Stencil receives copies of all masters used to create the drawing. This is the mechanism that makes a Visio drawing self-contained and allows others to view your drawings without having to have the stencils of the original masters loaded on their local machine.

Creating Masters

You can turn any shape on a drawing page into a master by dragging the shape and dropping it into a stencil that is writeable.

Try it! Creating a New Master

1. Draw a new shape, such as a red rectangle, on the drawing page.

2. Create a new stencil by choosing from the Shapes Window More Shapes > New Stencil.

3. Drag the rectangle shape from the drawing page into the stencil.

4. From the stencil window, right-click on the new master and choose Edit Master > Master Properties from the menu. In the Master Properties dialog box you can edit properties of the master, such as name, icon size, prompt, and so on.

5. Right-click on the master again and choose Edit Master > Edit Master Shape. This opens a new drawing window containing the master shape. From this window you can make changes to the master. When the window is closed, Visio will prompt you to save the changes to the master shape.

Editing Master Properties

The Master Properties dialog displays the following properties:

Nametext that appears with a master icon on a stencil

Prompttext that appears in tip balloon when you hover over the icon.

Icon sizenormal is the default but you can edit this.

Align Master Nameleft, right, and center (applies only when you choose View > Names Under Icons in the stencil window). Right click on the stencil title bar to see this menu.

Search Keywordsdata that is deposited in the User.visKeyword cell that is used to aid Search tool results.

Match master by name on dropif drawing already has a master of the same name, impose this masters formatting and geometry or use the other shapes formatting. If first shape has Match master by name on drop selected, then any subsequent master with the same name will look the same as the first master of that name dropped into the drawing.

Show live preview in Shapes Windowthe image shown with the master is a realistic rendering of the original shape image. There is also an icon generated when the master is first created. If show live preview is turned off, the icon is then displayed in the Shapes window.

Warning:

The icon is generated once when the master is first created. It is not updated if subsequent changes are made to the master. However, the icon can be edited at any time by choosing Edit Master > Edit Icon Image.

Tip:

You can copy an icon image from an Icon Editor window (like the one found in Microsoft Visual Studio) and paste it into the Icon Editor window in Visio.

0.

Try it! Master Properties

1. Right-click on a master and choose Edit Master > Master Properties. Edit the prompt in the Properties Dialog box.

2. Edit the default icon in the Icon Editor: Edit Master > Edit Icon Image

a. The default icon is a miniature of the shape itself, which is not always clear or appealing.

b. You can change the default icon using the Icon Editor.

3. Edit the Master in the Master editing window: Edit Master > Edit Master Shape

Try it! Match Master by Name on Drop

1. Open a new blank drawing, two new blank stencils (Shapes > More Shapes > New Stencil), and the document stencil (Shapes > More Shapes > Show Document Stencil).

2. Create a master in each blank stencil with the same names but different appearance, such as different fill colors.

3. In one of the masters, be sure that Match Master by Name on Drop is checked (right-click on a master and choose Edit Master > Master Properties).

4. Drag the master (which has Match master by name on drop selected) onto the drawing page.

5. Then drag the other shape of the same name onto the drawing page and notice what happens in the local stencil and the drawing page when you drop the second master onto the drawing page.

The second master dropped inherits the characteristics of the first shape dropped.

6. Delete all shapes from the local stencil and repeat the experiment by first dragging out the shape without Match Master by Name on Drop checked.

This time, the second shape does not inherit the characteristics of the first shape dropped.

Master Shortcuts

Try it! Create a Master Shortcut

1. If the stencil where you want to put the shortcut is not editable, right-click the title bar and then choose Edit Stencil. A small red dot is placed on the right side of the stencil title bar to indicate that the stencil is editable. Once edited this dot changes to the Save icon. If the stencil is floated the icon in the stencil title bar changes from (indicating that the stencil is read-only) to (indicating that the stencil is editable).

2. Press Ctrl+Shift while you drag the master from the original stencil to the stencil you opened for editing.

Note:

Master Shortcuts can only be created to masters in stencils that have been saved. If you create a new stencil and have not yet saved that stencil, then any attempt to create a Master Shortcut will create a copy instead.

0.

Try it! Set the Drop Action of a Master Shortcut

1. Right-click the Master shortcut in the editable stencil, and then choose Edit Master Shortcut > Master Shortcut Properties

2. In the Master Shortcut Properties dialog window, insert the following formula in the Drop actions text box:

Width=ThePage!PageWidth-1in

3. Close the dialog box.

4. Drag the shortcut into the drawing.

0.

When you drop a master shortcut onto a drawing page, the Visio application applies any drop actions in the shortcut to the newly created shape. Each drop action defines a particular value or formula to be assigned to a particular cell in the new shape.

Because drop actions are defined by the shortcut, not the target master, it is possible to create several shortcuts that refer to the same target master, but that produce very different effects when dropped onto the drawing page.

The DropActions property can be blank, or can define a series of one or more individual drop actions. Drop Actions are separated by semicolons. Each action consists of the name of the cell to change, followed by the formula to apply to that cell, separated by an equals sign ("="). For example:

User.SubType=3; FillForegnd=7

Instancing Masters

When you drag a master into a drawing, you create an instance of the master.

Try it! Instancing Masters I

1. From your student CD, open \Demos\Vol1\S1 Visio Platform Introduction\Platform Shapes.vss and instance the smart arrow master several times.

2. Modify the length and color of some of the instances to show they are still smart.

An instance of a master from a standalone stencil is not linked to the original master shape on the standalone stencil. Therefore, it doesnt inherit changes to the master that occur after the instance is created.

Try it! Instancing Masters II

1. Edit the master in the standalone stencil. Note that the instances of the master do not change.

2. The master is copied to the local stencil of the drawing the first time that master is dropped. The instance inherits from the local copy of the master.

Try it! Instancing Masters III

1. Display the Document Stencil alongside the drawing by choosing Shapes > More Shapes > Show Document Stencil.

2. Edit the master in the Document Stencil. Notice how the instances change.

3. Drag another shape from a standalone stencil into the drawing. Note that it shows up in Document Stencil under its own unique name.

Note:

A drawing file may also acquire additional settings from the master, such as themes and layers.

0.

Inheritance vs. Local Formatting

Instances inherit as much data as possible from local masters. However, when a user moves, stretches or otherwise interacts with a shape, local overrides occur.

For example, in the above illustration:

The left instance has no local overrides. It inherits everything from a local master. Pin position is local as it is based on the location of the shape on the page.

The middle instance inherits everything except width, which changed when the instance was resized horizontally.

The right instance still inherits smart geometry, but has local overrides for width, height, angle, and fill color.

0.

An instance can inherit many attributes from a local masterthese are only a few of the possibilities.

Note:

The advantage of inheritance is that it enables you to make global, consistent changes to many shapes by editing one master shape.

Identifying Local Overrides

You can see local overrides by displaying the instances ShapeSheet (and some dialog boxes as well).

Try it! Local Overrides

1. Select an instance with one local override, such as width.

2. Display its ShapeSheet.

3. Notice that a locally overridden formula is blue.

4. Black text is inherited data.

Note:

The PinX and PinY are always blue; these are not inherited because they are based on where the shape is dropped on the page. If a shape is drawn locally, all cells in the Shape Transform and Geometry sections contain local overrides and are blue.

0.

Try it! Inheritance

1. Open a stencil Shapes > More Shapes > General > Basic Shapes.

2. Drag the square shape onto the drawing page and open its ShapeSheet window. Note that the Width and Height cells have black text indicating that these cells are inherited. PinX and PinY are blue because there values are determined by the drop point when the shape was dropped and are therefore local overrides.

3. Move and resize the square on the page. Note that the text in the Width and Height cells turns blue.

4. To re-inherit the defaults for the master, select the cell that you want to re-inherit and type =, then the press the Enter key.

Visio File Extensions

Recall that each drawing contains a Document Stencil even if it is not visible by default. Drawings, stencils, and template files have the same internal structure and can contain the same things.

Tip:

Drawing files containing a Document Stencil is what allows the drawing to be self-contained, meaning it doesnt require access to the original stencil and template. Thus if you have created a custom stencil and used custom shapes in a drawing, you can send your drawing to another user who may not have that stencil. Of course, you can also include your stencil file with your drawing to enable access to the original master shapes.

The file extension determines how Visio displays the file:

The file extensions .vsd, .vdx, .vdw display a drawing.

The file extensions .vss and .vsx display a stencil.

The file extensions .vst and .vtx display a template, which provides page properties, drawing environment, and any predefined elements for new drawings.

Note:

The file formats for Visio 2010, Visio 2007, and Visio 2003 are compatible. The Visio 2002 file format is different. Any of these later versions of Visio can save back to the Visio 2002 format and can open any older file format.

Visio 2010 adds a new file type to the family, a .vdw file. The .vdw file type is created when saving a drawing as a web page. It contains the native Visio representation of the diagram (a .vsd file) and meta data used by Visio Services to render the web drawing in a browser. This meta data is regenerated on each save.

Try it! File Extensions

1. From the Shapes window menu, open a Visio stencil.

2. If the stencil is not editable, Right-click on the stencil title bar and choose Edit Stencil. Note that stencils delivered with Visio will have their file properties set to read-only, so the Edit Stencil menu will be inactive.

3. Right-click on the stencil title bar and choose Drawing Explorer. The Drawing Explorer window will be opened for the stencil.

4. Use the Drawing Explorer to explore the stencil. Note that it has Foreground and Background pages, Styles, Masters, and Patterns the same as a regular drawing file. The Masters collection shows each Master the stencil contains.

XML for Visio

Visio has defined an XML schema (vocabulary) that contains all the data from the Visio internal model. When a user creates a Visio XML file, all the data needed to describe the drawing, stencil or template is written to a file in XML form.

The Visio XML file format (.VDX, .VSX, .VTX) was designed to be a peer of the binary Visio file format (.VSD, .VSS, .VST). Users can access Visio XML files the same way as they access binary Visio files, and they can create and save Visio XML files using the Visio interface.

In addition, developers can use automation interface calls, (called DatadiagramML, a royalty free schema), to open, save, export and import XML for Visio files.

Try it! Create an XML for Visio file

1. Open a new Visio drawing.

2. Drag 2 or 3 shapes out onto the page.

3. From the File menu, choose Save As.

4. Give your drawing a name, and choose to save it to your desktop.

5. From the Save as type list, choose XML Drawing.

6. Click the Save button, and close the drawing.

7. Navigate to your desktop, and reopen the XML drawing file.

Visio loads the file and it is displayed just as a VSD file would be.

Templates

There are two primary reasons for using templates:

1. To speed up the drawing process.

2. To create consistent drawings.

A template is a convenient way to set up a new drawing exactly the way you want and to open any relevant stencils to be used with the drawing.

When a new drawing is created, based upon a template, the new drawing is a copy of the template, but created as a drawing file. This new drawing contains a copy of any drawing elements that were in the template and has the same drawing environment and workspace defined as the template.

Creating a Template

Try it! Create a template

1. Open \Demos\Vol1\S1 Visio Platform Introduction\Logo.vsd (has a company logo on the page).

2. Open a couple of stencils such as a flowchart or an organization chart stencil.

3. Save the drawing as FlowOrg.vst. Note that in the template the stencils were open.

4. Close and create a new drawing based on the template FlowOrg.vst. Notice that Visio creates a copy of the drawing.

Tip:

When you save a template, it will show in the File > New > Template Categories area only if it is saved somewhere in the current template path. This file path is set under File > Options > Advanced. Scroll all the way to the bottom of the screen and choose File Paths. Then add the file path for your template to the Templates file paths.

Add-Ons and Macros

In addition to creating your own master shapes and templates, the Visio solution developer can create new functionality to complement that which is delivered with the product. Several options are available to the developer.

The quick and easy way to create an add-on is to create a public procedure in a Visual Basic for Applications module. Visual Basic for Applications (VBA) code is kept as part of the drawing file and runs in the same memory space as Visio. However, many companies discourage this approach because of the perceived risk from viruses.

Visio supports COM add-ins and VSTO add-ins. Both are created as dynamic link libraries that can be loaded by Microsoft Office applications. A VSTO add-in runs on .NETs Common Language Runtime.

Stand alone solutions created as .exe files can be created with a variety of software development tools. You can use any .NET language within Visual Studio to build solutions for Visio including C#, Visual Basic, Visual C++ and Visual J++. Stand alone .exe files can be designed to started by Visio or to be launched outside of Visio. These run in their own memory space.

Note:

For more information on creating solutions for Visio, go to the MSDN Visio Developer Center web site at http://msdn.microsoft.com/en-us/office/aa905478.aspx.

The last type of add-on is the .vsl file. This is a dynamic link library for Visio that can be created with Microsoft Visual C++. These files are fast and also execute in the same memory space as Visio.

The Drawing Explorer

The Drawing Explorer can be used to display a hierarchical view of your document. Use it to add, delete, edit, and navigate to items in your drawing such as pages, shapes, masters, styles, patterns, and layers.

The Drawing Explorer can also be displayed for a stencil. Remember that a stencil and a drawing file are the same file type, just different file extensions. The Drawing Explorer for the stencil may also be accessed from any editable stencil with a right click to the stencil title bar.

Review: Visio Platform Introduction

Review questions

1. What is the distinction between designing with objects vs. drafting with graphic primitives?

2. What are the components of the Visio platform?

3. What are some reasons for using templates?

4. If you were to put information into the Prompt field in the Master Properties dialog, how does it become visible?

5. How can you tell if a ShapeSheet formula is inherited from a master, or if it has been locally overridden?

6. How do you force a formula to re-inherit from its master?

7. Name an advantage of using a master shortcut.

Answers

1. Designing with objects helps to turn the drawing into a complete model while drawing with graphic primitives just creates drawing elements with no particular meaning.

2. The Visio platform consists of the Drawing engine, automation interface, templates, stencils, masters, and add-ins.

3. Templates define the drawing environment including the stencils to be opened and can have pre-drawn elements. Using Templates speeds drawing creation and adds consistency to the results.

4. The text in the Prompt field is shown when the mouse is moved over the master in the stencil.

5. Inherited ShapeSheet cells have black text. Cells that have been locally overridden have blue text.

6. Select the cell and delete the contents or type an = into the cell.

7. Shortcuts can be used to create modifications to a master without creating an entirely new master.

Shapes and ShapeSheet Fundamentals

Overview

In this section well explore a variety of Visio SmartShapes symbols and note fundamental differences between them. Well also begin exploring the ShapeSheet environment and see how the textual format of ShapeSheet data is just another way of displaying the same drawing information that is seen in the drawing window view.

The ShapeSheet categorizes data about the shape into sections. Each section is made up of cells.

A cell contains a unit of information about the shape, such as its width or its height. Formulas can be stored in cells to give a shape intelligence by performing more complex tasks and by referencing information on other shapes within the drawing.

Types of Visio Shapes

There are many categories of Visio shapes: two-dimensional, one-dimensional, groups, guides, guide points, and foreign objects. Foreign objects are the shapes created when non-Visio data, such as bitmaps, metafiles, and controls, are added to a Visio drawing.

1-D and 2-D shapes

A shapes behavior can be categorized as either one-dimensional (1-D) or two-dimensional (2-D). Note that this has little or nothing to do with a shapes geometry.

A 1-D shape behaves like a line and displays a beginpoint and an endpoint that you can drag to reposition or to resize the shape. You can glue the beginpoint or the endpoint of 1-D shapes to the sides of 2-D shapes to create connecting lines that stay in place when the shapes are moved.

A 1-D shape has only one beginpoint and one endpoint. Some 1-D shapes also have other handles, such as this arc's control handle.

A 2-D shape behaves like a rectangle, and displays selection handles that you can drag to resize the shape when you select it with the pointer tool.

A 2-D shape has more than two handles and can be closed (like the ellipse) or open (like the wavy line).

Groups

A group is a shape that is composed of two or more shapes. A group can also include other groups and objects from other applications. A group can be moved and sized as a single shape, but its members can retain their original appearance and properties.

Guides

Guides are nonprinting lines on the drawing page used for alignment of shapes. These are dragged from the edge of the page rulers. A guide point is the crossbar-shaped guide that you drag from the intersection of the two rulers. Use these to quickly align and move shapes by gluing them to a guide or guide point.

Bitmaps and Metafiles

When a picture is inserted into a Visio drawing, Visio adds a shape wrapper to the object to give it handles so the user can interact with the object. Shape data can be added to these shapes.

Foreign Objects

When an ActiveX control or an embedded object from another application is added to a Visio drawing, Visio treats it as it does a bitmap or metafile. It creates a shape wrapper for the object.

Special types of Visio Shapes

There are a few other types of Visio shapes that provide special services within a Visio drawing. These include Containers, Callouts, Legends, and Backgrounds. See the section at the end of this module for more detail on these shapes.

Tip:

Thus all objects in a Visio drawing, whether they are created from masters, from the toolbar, or by inserting objects from outside of Visio, are in fact, shapes.

Visio Shapes as Parametric Objects

Visio shapes can be customized in many different ways because there are many different properties of shapes under the developers control. These properties are organized into categories of information and displayed to the user in a spreadsheet type interface called the ShapeSheet. Within the ShapeSheet you can find properties to control a shapes size and position, fill color, text and line formats, controls, connection points, and many other properties.

Try it! Shapes as Parametric Objects

To gain access to the ShapeSheet we first need to turn on the Developer tab in the Office Fluent UI. The Developer tab by default is not shown.

Tip:

To show the Developer tab choose File > Options > Advanced. Scroll to the bottom of the dialog to find the General section. Select Run in developer mode and choose OK. This not only displays the developer tab, it also makes available the Show ShapeSheet menu as a Right Mouse Action (RMA) on any shape.

1. Right click a shape and choose Show ShapeSheet. The graphical window and the ShapeSheet window are both visible by default.

2. Change the width of the shape in the graphical window. Note that the Width cell in the ShapeSheet window changes value.

Tip:

Shift-F7 will tile the windows vertically. Cntl-Shift-F7 will tile the windows horizontally.

3. Select the Width cell in the ShapeSheet window. Change its value. Note that the shape in the graphical window changes size.

The ShapeSheet view and the graphical view of the data are merely two views of the same data. If you change it in one view, that change is reflected in the other.

Even internally, Visio implements graphical changes by changing values in ShapeSheet cells.

Note:

When you begin to control Visio through automation, you will control it by manipulating ShapeSheet cells. The changes you make to cell values will immediately be reflected in the graphical view of the data.

Visio ShapeSheet Environment

When the ShapeSheet window is displayed a ShapeSheet Tools Design tab is displayed. This tab gives access to a variety of ShapeSheet features.

ShapeSheet cells can be viewed in two ways: as the formula or expression stored in the cell or as the evaluated result of the formula. The Formulas button in the View group toggles the ShapeSheet display from Formula view to Values view. The view can also be changed with a Right-click on a cell in the ShapeSheet window.

ShapeSheet cells can be edited. Select a cell. Notice that an edit line called the formula bar appears below the Visio menus. You can type a formula into the formula bar, or right into the ShapeSheet cell itself. In Visio, you must be careful to accept the contents of the edit line into the cell by selecting the blue check mark or by pressing the enter key.

Tip:

If the formula in a cell is very complex, choose the Edit Formula button from the Editing group on the ribbon. This opens the Edit Formula dialog which provides a lot more space for working with the formula. Add spaces and carriage returns in the Edit Formula dialog to make the formula more readable. The extra white space and carriage returns are removed from the formula when the dialog is closed.

Unlike other spreadsheet applications, Visios ShapeSheet displays categories of shape parameters in ShapeSheet sections. You can control the viewing of these sections in two ways:

1. Turn the display of a section on or off completely with View > Sections.

2. Reduce the size of a displayed section by clicking its title bar. The section will be reduced to just the name of the section displayed in the title bar.

Adding additional sections to shapes adds new behaviors, such as the ability to store shape data, user-defined cells, controls, and connection points. Each of these behaviors is created by first adding the appropriate section to the shapes ShapeSheet. Use Sections > Insert to display the Insert Sections dialog.

Note:

Menu tabs in Visio are context sensitive. When the ShapeSheet window has focus, the ShapeSheet Tools Design tab is displayed and reflects actions pertinent to the ShapeSheet environment.

One of the things you cannot do in the ShapeSheet is to rearrange sections. Viewing ShapeSheet cells that are visually separated can be made easier by using the View > Sections menu to turn off the display of sections not being used.

Tip:

The default setting in Visio is to display each ShapeSheet in the same window. This is not good if you need to look at more than one ShapeSheet at a time. To open multiple ShapeSheet windows choose File > Options > Advanced and scroll to the bottom to find the General section. Uncheck the option Open each ShapeSheet in the same window.

Review: Shapes and ShapeSheet Fundamentals

Review questions

1. Name three shape types that Visio supports.

2. What are the two different shape parameter views in the ShapeSheet?

3. Why are Visio shapes considered to be parametric objects?

Answers

1. 1D, 2D, Groups, Guides, GuidePoints, and embedded or foreign objects.

2. View Values and View Formulas.

3. Values can be set (like parameters) for ShapeSheet cells that hold the properties of the shape.

Defining Parametric Behavior

ShapeSheet Overview

In the last module you learned that the ShapeSheet contains cells that define properties of a shape and that these cells are a text view of the shape data. You have already examined the Width and Height cells in the Shape Transform section. Now you will learn how to create more complex behaviors in a shape by storing formulas in the ShapeSheet cells.

The Shape Transform section contains information about a shapes position and orientation.

The Geometry section of a shape defines paths for a shape. Each geometry section defines one path defined on x,y pairs called vertices. For example, a shape with a hole requires at least two geometry sections.

You can even define shape behaviors to refer to one shape from another. Most typically this method is used to allow group members to interact with each other.

In this section you will learn some of the advantages and disadvantages to creating Groups in Visio.

As you may have already noticed, many shapes in Visio are very detailed models of their real world counterparts. Shape Operations help cut down on complex shape development time, while providing an alternative development option to using groups.

The term Multishape comes from the ability to represent multiple shapes within one master shape. You will look at an example of a native Visio Multishape, and create one of your own.

Making a Smart Arrow

Try it! Draw a Single-Headed Arrow

1. Using the Line tool (Home tab > Tools), draw a single-headed arrow that is 3 inches wide and 2 inches high (at the base of the tip).

2. Ctrl-drag a duplicate of the arrow and note how the arrowhead is distorted when the arrow's width is changed.

The goal is to make sure that all of the growth occurs in the shaft of the arrow, so the arrowhead does not distort when the arrow is lengthened.

This is achieved by putting a new formula (Width 1 in) in the ShapeSheet cells that represent the four vertices at the base of the arrowhead.

Making a Smart Arrow (Continued)

Try it! Smart Arrow

A Smart arrow keeps the angle of the arrowhead constant when stretched horizontally.

1. Open the ShapeSheet for the new arrow.

2. Look for the first X Cell in the Geometry 1 Section, which contains a reference to Width * 0.666.

3. Edit that cell and replace the formula with Width - 1 in

4. Edit the remaining cells containing the formula Width*0.666 to reference the cell just edited.

5. To do this, click in the cell where you want to place the reference and type =.

6. Then click in the cell containing the formula you want to reference and click the Enter key to set the formula.

7. For example, if the cell Geometry1.X2 contained the formula Width - 1 in then set the cell reference for each of the other three cells to Geometry1.X2.

Controlling Geometry with Formulas

Stretch the arrow in height and observe what happens. The smart arrow weve just created is smart when stretched in length, but not smart when stretched in height.

The arrow would look better if all instances had similar-looking arrowheads, regardless of width or height. The arrowhead should maintain a constant angle, regardless of its width or height.

Another way to view the problem is to look at the arrowheads aspect ratio. The arrowhead maintains a constant aspect ratio if its width and height maintain a constant proportion. Here is another example. Suppose you have a dining room table that is one and one-half times as long as it is wide. If you measure its length to be 36 inches, you can calculate that its width to be 24 inches.

Set up formulas in the arrows geometry section that ensure the width of the arrowhead will be a proportion of the height of the shape rather than the constant value of 1 inch used in the earlier example.

Try it! Controlling Geometry

1. In the previous example, find the cell containing the formula

Width 1 in

2. Replace this formula with the new formula Width Height/2

The Shape Transform Section

The Shape Transform section determines a shapes width and height, its position, and its orientation relative to its parent.

Shape Transform Cell

Description

Width and Height

Constants in page coordinates

Angle

Angle of rotation, where original X-axis is 0 degrees

PinX

X ordinate of Pin relative to the shapes parent (group or page)

PinY

Y ordinate of Pin relative to the shapes parent

LocPinX

X ordinate of Pin relative to the Shape

LocPinY

Y ordinate of Pin relative to the Shape

FlipX

toggle (1 or 0) indicating whether shape has been flipped in X

FlipY

toggle (1 or 0) indicating whether shape has been flipped in Y

ResizeMode

Resize behavior (0, 1, or 2); relevant only if a shape is in a group

The pin is expressed in the coordinate system of the shapes parent.

The local pin is expressed in the coordinate system of the shape.

The Geometry Section

A shapes path is recorded as a series of X, Y coordinate pairs called vertices. It is measured from a point of origin for the shape and connected with line, arc, or spline segments between the vertices.

In Visio, each row in the Geometry section defines one vertex.

Default formulas for vertex locations refer to the shapes width and height. You can control a shapes vertices by writing your own formulas in the shapes Geometry section.

Try it! ShapeSheet Geometry

1. Using the Rectangle tool, create a rectangle of any reasonable size.

2. Display the Geometry section in the ShapeSheet

3. Note that a Geometry section represents a single path, and a shape can have more than one Geometry section.

4. Note that default X and Y formulas refer to the shapes Width and Height.

Coordinates in Visio

To control a shapes size or position, you describe it in terms of a Cartesian coordinate system. The coordinate system for the page is expressed the same way. The origin is in the lower left corner of the page. The positive X direction corresponds to the pages width. The positive Y direction corresponds to the pages height.

Note:

The origin remains the same, even if the ruler view of the page has been changed.

A shape always resides on a page. The page can be thought of as the parent of the shapes it contains.

Each shape has its own local coordinate system similar to that of the page. A shapes origin is in the lower left corner of the shapes alignment box. The positive X direction corresponds to a shapes width and the positive Y direction corresponds to a shapes height.

Parent Coordinates

The parent coordinate system of the shape is the local coordinate system of the shapes parent. The parent of a shape is the page unless the shape is a member of a group, in which case the group is the parent.

The coordinate system of a group is defined in the same way as the coordinate system of a shape.

The page is the ultimate parent of all of the shapes it contains.

The Shape Transform section uses units of measure of the parent coordinate system to represent a shapes width, height, and position on the page.

Try it! Parent Coordinates

1. Create the following shapes and group them together: a circle, a triangle, and a square.

2. Display the Size & Position window (View > Task Panes > Size & Position). Drag the group on the page and notice the X and Y locations of the shape are in the coordinates of the page.

3. Sub select a member of the group. Note that its X and Y locations are in the coordinate of the group with the groups origin being in its lower left corner.

The Pin Secures the Shape to the Page

Heres how to think about coordinates in Visio:

To place a shape on a page, poke an imaginary hole through the shape to pin it to the page.

Two imaginary holes are formed, one in the page and one in the shape.

The location of the imaginary hole in the page is kept in PinX and PinY. These pin values are expressed in the coordinate system of the page (the shapes parent).

The location of the imaginary hole in the shape is kept in LocPinX and LocPinY. These pin values are expressed in the coordinate system of the shape.

Here is more information about the pin:

The pin is the point around which a shape is rotated and flipped.

The pin in Visio is equivalent to the insertion point or reference point in CAD. The mouse position at which you drop the master becomes the pin position of the new shape.

Moving the entire shape changes the Pin values in the ShapeSheet.

Moving the pin relative to the shape changes the LocPin values.

Use the Rotation tool (hovering over the rotation tool handle for a moment causes the Pin to be displayed) to display and move the pin. (Or edit the LocPin cells in the ShapeSheet.)

Try it! The Pin

1. Open \Demos\Vol1\S3 Defining Parametric Behavior\Parametric Shapes.vss.

2. Drag the generic S-shape from the stencil onto the drawing window.

3. Click on the rotation handle and rotate it. Analyze the default pin location, which is in the center of the shape.

4. Drag the pin far off-center.

5. Rotate the shape and see how it moves about the new pin position.

Lab 1.1: Create a Directed Graph Shape

Points to Consider

1. The vertex representing the pointed end of the shape is beyond the width of the shape. Therefore the formula will be a derivative of Width+?

2. The 45 degree angle will remain constant if the shapes height is changed.

Challenge:

To enhance the utility of the shape change the formula in the Width cell to: =GUARD(EVALTEXT(TheText))

Experiment by changing the text of the shape and noting the effect on the shapes size. Try different units as well and note that the default units used by Visio are inches when no unit is entered

Referring to Other Shapes

A shapes name will typically be the master name for an instance of a master. However, when more than one instance of a shape exists, Visio will make the names unique. To do this, the shape ID is appended to the name. You can find out a shapes name by displaying the Shape Name dialog box, or by looking at the title bar for the ShapeSheet window.

Note:

The Shape Name dialog is accessed from the Developer tab.

Try it! Sheet IDs

1. Draw a rectangle on the drawing page.

2. Open the Shape Name dialog and note the name, shape type and ID.

3. Display the ShapeSheet; note the name is also displayed in the title bar of the ShapeSheet.

Try it! Intershape References

1. Draw three rectangles that are red, green, and blue.

2. Name them Red, Green, and Blue using the Shape Name dialog.

3. Set the height of the green rectangle as shown: Height=GUARD(Red!Height).

4. Change the height of the red rectangle. Notice that the height of the green rectangle also changes.

5. Group Red and Green.

6. Set the height of the blue rectangle as shown: Height=GUARD(Red!Height). An error occurs because they are not at the same scope level.

7. Set the height of the blue rectangle as shown: Height=GUARD(Sheet.1!Height). This works. (Note that Sheet.1 is shown here as an example. Check the Shape Name dialog to get the actual shape ID value.)

Note:

Every shape can be referred to by its sheet.id name. Use the Shape Name dialog to get the shapes id value..

Scope of Intershape References

Whether you can refer to a shape by name, and the exact syntax youll use, depends on the location and scope of the shape youre referring to, relative to the shape with the reference.

If a shape is a peer of the shape with the reference, you can refer to that shape by name. For example, if the peer shape is in the same group, you can refer to its name directly.

You cannot refer by name to a shape above or below the shapes own peer level. For example, if the peer shape is a group, you cannot refer to its members by name.

However, you can use Sheet.ID syntax to refer to any shape on the page, regardless of the level.

For example, if Arm is the group shape, Sleeves Width formula must be

= Sheet.3!Width - Hand!Width

Because Arm is Sleeves parent, Sleeve cannot refer to Arm by any name other than its Sheet.ID name.

Groups

Grouping creates a new shape that includes all the original shapes, without altering the shapes themselves. Use a group when you want several shapes to move and size together, but keep their individual formatting attributes.

The Group command adds a ShapeSheet for the group and modifies formulas in the members ShapeSheet windows to refer to the group. Formulas that referred to page coordinates now refer to the groups coordinate system because the group is now the parent.

When you ungroup, the process is reversed and the groups ShapeSheet is deleted.

Tip:

For this reason, it is a good idea to group shapes before defining custom formulas in the member shapes because they often refer to the groups ShapeSheet. Also, complete the final look of the shape before you group it and add custom formulas to the group shape.

You can nest groups within groups, but for best performance, keep the number and level to a minimum and use intershape cell references sparingly.

Controlling Resize Behavior in Groups

When a group is resized, consider how the size and position of its members should change within the group.

By default, member shapes are stretched and repositioned to maintain proportions in the groups coordinate system.

If a member shape represents an object with fixed physical dimensionsfor example, a sink in a kitchen countertopyou want everything but the sink to stretch, so you would set it to Reposition Only in the Behavior dialog box (or 1 in the ResizeMode cell in Shape Transform).

Try it! Comparing Resize Modes

1. Create an ellipse and a square, and make a copy of each so you have two sets of similar shapes.

2. Open the Behavior dialog (from the Developer tab) and change the Resize behavior to Reposition only for each shape in one set (or set ResizeMode=1 in the ShapeSheet).

3. Group each set of shapes.

4. Resize both groups. The members that you set to Reposition only will move but not change size.

1.

Controlling Group Behavior

When Snap to member shapes is selected, you can snap and glue to member shapes within the group.

Note:

If you arent getting the snap and glue behavior you are expecting, check the settings in the Snap & Glue dialog (View tab > Visual Aids) to verify the current settings.

The group shape or parent can have its own text. When Edit text of group is selected (the default behavior), you can edit the text of the group. When this group feature is unchecked, when the shape is selected and the user starts to type, the text will go into the sub-level shape with the highest Z order.

You can change the default Z order that Visio imposes using the Shape > Order menu.

Although the sheet number and Z order may match when shapes are dropped on the page, sheet number does not determine the Z order. They very easily become unsynchronized due to these factors:

1. Sheet numbers are reused. For example, drop 3 shapes on a page that partially overlap. Delete the Sheet.2 shape. Add another shape (it is now Sheet.2) and its Z order is on top of Sheet.3.

2. If you change the Z order using the Shape > Order menu for one shape, then the Sheet ID no longer matches the Z order.

When Accept dropped shapes is checked, the group has the ability to accept shapes that are dragged into the group, incorporating the new shape as a new member. An example of this can be found in Rack 2000 Demo.vsd file on your student CD.

Note:

For a shape to be accepted as a new member of a group, you must select Developer > Behavior > Add shape to groups on drop option for the individual shapes. Also the group shape must be set to Accept dropped shapes.

Controlling Group Behavior (Continued)

When designing complex SmartShape symbols, one of the considerations you will need to make is the amount of interaction you want to allow with members of a group.

Users can select and interact with members of a group without opening the group edit window (right mouse select a group and choose Group > Open Group). Visio gives control over this group interaction behavior using the Selection order list.

Group only specifies that when you click to select a group, only the group is selected. The sub-selection mechanism is unavailable.

Tip:

You would want to implement this feature if you have group shape whose members need to remain in a specific location, in order to maintain functional or graphic integrity.

The Group first selection specifies that when you click to select a group, the group is selected first, with subsequent clicks selecting the individual members. This is Visios default Selection behavior.

Members first specify the opposite of Group first, with the click selection going to a member shape first. The group shape becomes the selection when you either select the bounding box for the group, or a member shape is clicked on a second time.

Manipulating Group data selections sets the group display order for text or shapes in a group.

Selecting Hide will hide the groups components except for connection points and control handles. Behind member shapes specifies to place the groups components behind the shapes within the group. In front of member shapes does the opposite of Behind member shapes, and is the default Visio Group data setting.

Shape Operations

Not all requirements can be met with simple shapes. You may already be familiar with commands from the Developer > Operations menu:

Union, Combine, Fragment, Intersect, and Subtract.

These are useful techniques for constructing shapes with complex geometries or shapes that would be hard to draw with line segments and arcs.

Tip:

All of these commands destroy the original shapes along with their formulas, so wait to add smart formulas until after the operation.

Try it! Combining Shapes

1. Drag over a rectangle, a square, and a circle. Make sure they overlap one another and fill them with different colors.

2. Duplicate the set of shapes until you have six sets total.

3. In the first set, select first the circle shape, then the other two, and choose Shape > Operations > Union.

4. In the second set, choose Combine; in the third set, choose Fragment, and so on until you have done each operation.

5. Note how they behave differently.

6. Using the sixth set of shapes, select the square or rectangle first and again choose Combine. How is it different than the last time?

7. Display the ShapeSheet for one of the newly combined shapes.

Note:

Combine creates a single shape with multiple paths (Geometry sections). The new shape has the same formatting properties as the first shape selected. Paths are created in shape selection order.

Creating a Multishape

Try it! Analyze a Multishape

1. Drag out an instance of the Flowchart shapes from Parametric Shapes.vss.

2. Note that you can modify the appearance of the shape by making a selection from the Right-click menu.

3. Open the ShapeSheet and analyze how the multishape behavior has been implemented.

1.

Try it! Create a Multishape

1. Draw two rectangles, one placed vertically and one placed horizontally, and position them over each other to form a plus sign.

2. Use Developer > Operations > Combine to create a new shape with multiple paths.

3. Add a User-defined cell called State, and enter the value 1.

4. Add an Actions section and add one row for each Geometry section.

5. Set each Action cell formula to =SETF(User.State, 1) for the first row, 2 for the second.

6. Set one Menu cell to Horizontal, the other to Vertical.

Assume that the action in the first row of the Actions section corresponds to the first Geometry section, and the second row corresponds to the second.

7. Set the NoShow cell as follows:

Geometry1.NoShow =NOT(User.State = 2)Geometry2.NoShow =NOT(User.State = 1)

Note:

The NOT function returns 1 if the expression is false and 0 if it is true. When you choose one of the actions, SETF sets User.State to the corresponding number. The NoShow formula then evaluates to 0, which shows that component of the multishape.

Lab 1.2: Multishapes and Actions

Points to Consider

1. Can create a group shape, but it is more difficult than a combined shape.

2. State of User-defined cell determines NoShow values of arm geometry sections.

Challenge:

Display Show or Hide in the right-mouse menu depending on the current status of the shape. Here, only one action row would be necessary.

Review: Defining Parametric Behavior

Review questions

1. What cells determine a shapes position?

2. What type of coordinate system is used in Visio?

3. What is an Intershape reference? Can you think of examples where they might be useful?

4. What would the formula in a group member shapes Width cell refer to?

5. Under what circumstances would you choose to set the Selection mode for a group shape to Group only?

6. Name an advantage of using a shape operation to build a complex shape over using a group to build the same shape?

Answers

1. PinX and PinY.

2. Cartesian

3. Referencing a shape cell in one shape from another shape. Useful anytime dependencies are desired between shapes.

4. It refers to the parent groups Width cell. The formula by default allows the member shape to resize with the group.

5. Use Group only selection mode anytime users should not be able to select the member shapes of the group.

6. Complex geometry paths can sometimes be created more easily using shape operations than using the drawing tools.

Defining Text Behavior

Overview

You can create Visio shapes that will provide your users with the ability to add text easily, and interact with that text intuitively. In this section you will learn how to add text to shapes and how to enhance basic text behavior using formulas.

Objectives

Build shapes with smarter text behavior.

Resize text when the shape is resized.

Add text to shapes and control the position of text through the Visio UI.

Control text using the Text Transform section of the ShapeSheet. This section has cells for controlling text size, position, and orientation.

Use text fields to create dynamic text that references some piece of data. You can use text fields to display information about the shape, page, or document.

Manipulate complex text layouts on shapes. This could include the use of multiple text blocks within a single shape. This often simplifies user interaction with this text, and allows for more information about the shape to be displayed.

Text Tools

You can use two tools from the user interface to manipulate text: the Text tool and the Text Block tool. These are located on the Home tab in the Tools group.

Text Tool

Use the Text tool to create a text block on the drawing page or activate a text block so you can edit the text. To create new freestanding text, choose the Text tool to place an insertion point, and then type. The text appears to have no shape, but as you learned earlier, everything is a shape.

Try it! Text Properties

1. Create some text using the Text tool.

2. Select the shape and view its ShapeSheet

3. Note that it has a Geometry section.

4. Select the text and choose format the shape with Home > Line. This is in the Shape group of the Home tab. Note that the line pattern is set to None. Close the dialog and choose Fill. Note that the fill pattern is also set to None. Changing the line and fill patterns makes the text shape look just like a rectangle with some text applied. Thats all it really is!

If you want the text block to be a certain size, drag to create an area of the width you want, and then type.

To add text to a shape or replace all of a shape's text with new text, select the shape with any tool and start typing.

Text Block Tool

Use the text block tool to select a shape's text block. You can size, move, and rotate the text block independently of its shape.

To rotate a text block, select a rotation handle, and then drag. To move a shapes text block, click inside the center of the shape or on the green border, and then drag. To size a shapes text block, click one of the selection handles, and then drag.

Text and the Text Block

Visio shapes have built-in text contained in the shapes text block. The text block has its own coordinate system independent of the shapes geometry.

Try it! Text Behavior Basics I

1. Open \Demos\Vol1\S4 Defining Text Behavior\Text Shapes.vss.

2. Drag over the Basic shape and use the Text Block tool to move, rotate, and resize the text block.

The text block is similar to a page in a word processor.

The text wraps at the margins and grows vertically.

3. Notice the differences between the Text tool and the Text Block tool. When using the Text Block tool, the size and angle of the text block are displayed in the status bar.

4. The text coordinate system is positioned relative to the shapes local pin. By default it is the same size as the shapes alignment box.

You can also control the text behavior from the ShapeSheet.

Text Position

The default behavior for text is for it to be centered within its text block.

Text can be offset in a number of ways. From the Home tab open the Font group to display the Text dialog. Use the Text tabbed dialog to change the location of the text. To set the text vertically to the top, middle, or bottom, use the Text Block tab and select from the Alignment dropdown list as shown in the diagram below.

To offset the text horizontally to the left, center, or right choose the Paragraph tab and select from the Alignment dropdown as shown in the next diagram.

Note:

Control handles are not part of the printed page so they will not distort the shapes appearance.

Controlling Text Position in the ShapeSheet

The Text Transform section of the ShapeSheet contains formulas and values for the text blocks size, angle, and location.

To show the Text Transform section in the ShapeSheet, click anywhere in the ShapeSheet to make the ShapeSheet window active and select Insert Section . Add a check mark next to Text Transform. If Text Transform is inactive in this dialog it means the Text Transform is already a part of the ShapeSheet. Scroll down in the ShapeSheet until it is found.

The Text Transform section is nearly identical to the Shape Transform section of the shape, except that Text Transform does not have the FlipX, FlipY, and ResizeMode cells.

The Text Transform section describes the location of the text block relative to its parent coordinates. The parent of the text block is the shape itself.

The default formulas in TxtPinX and TxtPinY refer to the shapes Width and Height.

The default formulas in TxtLocPinX and TxtLocPinY refer to TxtWidth and TxtHeight.

Try it! Text Behavior Basics II

1. Draw a rectangle, and display the Text Transform section. Do this by choosing the Insert > Section menu item with the ShapeSheet window active, or use the Text Block tool to move the text box.

2. Visio assumes default behavior and does not automatically display it in the ShapeSheet. The Text Transform section will not display in the ShapeSheet until the user has either changed it using the Text Block tool, or added it to the ShapeSheet with the Insert Section menu.

Text Rotation

In addition to deciding where to place text, youll need to consider the appropriate angle for the text.

By default, the text angle corresponds to the angle of the shape. Therefore, when you rotate the shape, you rotate the text as well.

However, sometimes you want to rotate a shapes text independently of the shape itself.

The angle of the text (TxtAngle) is relative to the shapes rotation, so a TxtAngle value greater than 0.0 adds to the shapes angle; it rotates the text more than the shape.

There are three common text rotation scenarios:

Text that rotates with the shape.

Text that stays level with the bottom of the drawing, no matter how the shape is rotated.

Text that rotates with the shape but stays readable, which is commonly known as gravity text.

Default Text Behavior

For example, the text in a stop-sign shape should be oriented to the direction of travel on the road, not to the drawing page. Therefore, the text angle should match the shapes angle (TxtAngle=0 deg).

Level Text

In some cases you will want text to be readable from the bottom of the page. Because the TxtAngle is relative to the shape, you can counter-rotate against the shapes angle to keep the text level at all times.

Try it! Text Rotation

1. Instance the 2-D arrow shape.

2. To counter-rotate, enter the formula = Angle into the TxtAngle cell.

3. Rotate the shape. Notice that this works well until you flip the shape. Once the shape is flipped, it cancels the counter-rotations negative sign. When the shape is flipped, a clockwise rotation in the shape's coordinate system is a counter-clockwise rotation in the parent coordinate system.

4. To fix the problem caused by flipping the shape, replace the previous formula in the TxtAngle cell with =IF(BITXOR( FlipX, FlipY ), Angle, Angle).

Gravity Text

Visio has a GRAVITY function that allows you to make text readable from the bottom or the right-hand side of the page. The text rotates with the shape to a certain extent, but counter-rotates as needed.

The GRAVITY function has optional second and third parameters that default to 90 degrees and 270 degrees, respectively.

The slide shows an example of the behavior of a line shape with text when it is rotated through 360 degrees. When the Gravity function is used, the text automatically rights itself as the shape passes through 90 degrees and through 270 degrees.

Try it! Gravity text

1. Use the drawing tools to create an arrow shape 3 inches wide by 2 inches high.

2. Edit the ShapeSheet to add Gravity text to the shape so that it flips as the shape is rotated.

Text Fields

A text block can have text fields, which are placeholders to display drawing or shape information.

Try it! Text Fields

1. Instance the 2-D arrow shape and ensure the shape is selected.

2. From the Visio ribbon, choose Insert tab > Field.

3. Look at the various options in the Insert Field dialog box.

4. Insert a field to make the arrow display todays date. Under Category, choose Date/Time and under Field, choose Current Date/Time. Select the Data Format button and choose one of the date/time formats. Select OK twice to close the dialogs.

5. Change the field information to show how the arrow can be used to display size and placement angle.

Tip:

Multiple text fields can be added to a shape. The field will be placed at your edit insertion point. If there is text selected, that text will be replaced with the new field. If an existing text field is selected, that text field will be replaced with the new text field..

6. Add the word Angle = to the text block, and then add a second text field to display the angle of the shape. Remember that fields and regular text can be mixed.

If youve designed a text block to display field information, you will probably want to deny the user text-editing privileges. You can protect against the user changing these fields by locking the shapes text. Set the LockTextEdit cell in the Protection section of the ShapeSheet to 1 or True to prevent a user from tampering with a shapes text.

Note:

We will look at shape protection issues in more detail in later in this module.

Note the Custom Formula field under Category in the Text Field dialog box. Using this option, virtually any information about a shape or the page can be displayed as text.

Text Field Custom Formulas

One of the categories to choose from in the Text Field dialog is Custom Formulas. Use Custom Formulas in text fields the same way you would use them in the ShapeSheet.

The FORMAT function can be used in conjunction with Custom Formula. It takes a string argument that contains the following codes:

Character

Type

Description

#

Digit.

Does not display leading or trailing zeros; the fractional portion is rounded

0

Digit

Displays leading or trailing zeroes

U or u

Unit.

Displays abbreviated unit label. For example, in or deg

UU or uu

Unit.

Displays long unit label. For example, inches or degrees

Try it! Format Function

1. Instance another arrow.

2. Insert the custom formula: =FORMAT(NOW(),"MMM dd, yyyy hh:mm"). Both FORMAT and NOW are functions. FORMAT is used to format a string. NOW returns the current date and time.

Note:

Custom formulas are stored in the ShapeSheet in the Text Fields section. You cannot add new formulas by adding rows to the Fields section in the ShapeSheet, but you can modify already existing custom formulas directly from the ShapeSheet.

Resize Shapes with Formulas

Visio allows the text block to grow beyond the height of the shape. Instead of having the user correct the shapes size to accommodate the text spillage, what about making the shape resize to accommodate the amount of text automatically?

To accomplish this, you can use the TEXTWIDTH and TEXTHEIGHT functions, which return the text extents, including text block margins, and the spacing between lines.

Try it! Shape Height that Resizes with the Text

1. From your student CD, open \Vol1\S4 Defining Text Behavior\Text Shape.vss.

2. Instance the Word Balloon and type too much text in it.

3. As you enter more text, it exceeds the text block. In order for a shape to tightly enclose its text, the shapes width and height must be a function of the text block and text extents.

4. In the Height cell, enter the formula:

=GUARD(TEXTHEIGHT(TheText, Width))

TheTextrefers to all the text of the shape

Widthwidth allowed (the width to break lines to)

Now the Word Balloon will tightly enclose any amount of text entered.

1.

Try it! Shape Width that Resizes with the Text

1. Draw a rectangle and open its ShapeSheet.

2. Set

Width=GUARD(TEXTWIDTH(TheText))

3. Note how the width of the shape grows to accommodate the text.

1.

Text Resizing Behavior

Another important question is whether the text and shape sizes should correspond. Visios default behavior is to keep the original font size when the shape is resized. But in a real-world object such as a speed-limit sign, the shape and its text should resize proportionately.

Font size is a function of changes in a shapes dimensions. To resize the font you can apply a conversion ratio that represents how the shapes dimensions have changed.

Many shapes, such as the speed-limit sign resize proportionally in both the X and Y axes. You need to relate the font to just one axis, for example, Height.

Char.Size=(Height/Original height)* (Original font size)

Try it! Text that Resizes with the Shape

1. Drag out a rectangle.

2. Create a User-defined cell called FontSize.

Remember, storing smart formulas in User-defined cells optimizes shape performance and maintenance.

3. Enter in the font size conversion ratio

Here is an example: (Height/1 in)*(12pt)

4. Set the Char.Size cell to refer to User.FontSize.

5. In the Protection section, set LockAspect to 1.

6. Resize the shape and note what happens.

Multiple Text Blocks

Recall that a group is composed of nested shapes, each having its own text block. There are several advantages to having multiple text blocks:

Each can be positioned independently.

Each can be edited independently.

Each can have different text styles and text block attributes, including vertical alignments.

Note that in Visio, a single text block can only have one style applied to it. Unlike word processors, styles are not assigned to individual paragraphs.

This School Zone sign could have only one text block, but if you ever intend to edit it, more than one would be better.

The "15" should be the default text in the shape, so the speed limit can be changed easily by selecting the shape, and typing a new value.

Note:

The parent shape (group shape) accepts the default text for the group.

Tip:

You can create shapes that have text only (no fill or lines) by dragging out a rectangle with the Text tool, and then typing some text. If you do not type any text, the shape will be automatically deleted when you click away from it.

Try it! School Zone Sign

1. Draw a rectangle and use the Corner Rounding tool to make it look accurate.

2. Using the Text Tool, add a text block for the School Zone text, and format it accordingly.

3. Open its ShapeSheet and add a User-defined cell called FontSize.

4. Enter in the font size conversion ratio.

5. Set the Char.Size cell to refer to User.FontSize.

Make sure to Guard this formula.

6. Copy the School Zone text block and change the text to MPH.

7. Position the text blocks, and group them with the sign shape.

8. Select the sign shape again and type in the speed limit. Format it accordingly.

Remember, you are working with the groups text block here.

9. Repeat steps 3, 4 and 5 for the group shape.

10. In the Protection section for the group, set LockAspect to 1.

11. Select the sign shape, and from the Format menu, choose Behavior. From the Selection list, choose Group only.

This prevents the other text blocks from being selected.

12. Test your smart text behavior by changing the size of your shape.

Lab 1.3: Controlling Text Blocks

Points to Consider

1. The Speed Limit and MPH text blocks will be members of the final group shape.

2. The text block that will hold the speed limit number will be the text block of the group shape.

3. Users should not be able to sub-select the Speed Limit and MPH text blocks.

4. Make sure to Guard your formulas.

Review: Defining Text Behavior

Text can be added to shapes. By default, the text block has the same size and orientation as the shape. Here are some questions relating to the material you just covered.

Review Questions

1. How can the text block be changed from the user interface?

2. How do you display the Text Transform section in the ShapeSheet?

3. Can a shape have multiple text fields?

4. What two ShapeSheet functions would you use to make the shape resize to accommodate the amount of text entered in it?

5. Name two advantages of using multiple text blocks in a shape.

6. What is the best tool to use for creating multiple text blocks?

Answers

1. Use the Text Block tool.

2. Use Insert > Section or just move the text block with the Text Block tool.

3. Yes

4. TEXTWIDTH and TEXTHEIGHT

5. Easier to position and format individual text blocks.

6. Use the Text tool to create additional text block.

Defining Page Environment

Overview

In Visio, the user has control over drawing page size and scale. This information is maintained as part of the pages ShapeSheet. Recall that everything in a Visio drawing is a shape.

Objectives

Control shape behavior such as title block size and position by referencing properties of the Page.

Modify the size and scale of a page using the Page Setup dialog.

Information about the page is kept in the pages ShapeSheet. It has a Page Properties section, which is similar to the shapes Shape Transform section.

Stack Pages like transparencies by creating background pages and associating background pages to foreground pages. When viewing a foreground page, any information on the background page shows through.

Categorize shapes by assigning shapes to Layers. Masters can be pre-assigned to multiple layers.

Page Setup Dialog

The Page Setup menu can be used to modify properties of the page. The Page Setup dialog is accessed from the Design tab.

Try it! Page Setup

1. Choose Design > Page Setup to display the Page Setup dialog box shown above.

2. Modify the page size on the Page Size tab. Note that you can choose several standard sizes after first selecting from either Standard, Metric (ISO), ANSI Engineering, or ANSI Architectural.

3. Modify the page scale on the Drawing Scale tab. Note that you can choose several standard scales or set a custom scale.

Note:

Printer setup control has its own tab called Print Setup.

Page's ShapeSheet is known as the PageSheet

Information about a page can be viewed in the pages ShapeSheet.

The pages ShapeSheet, a.k.a PageSheet can be displayed from the Developer tab. Choose the Show ShapeSheet dropdown and select Page.

If you are running in Developer mode, just right-click on the page and choose Show ShapeSheet.

Note:

Observe the PageWidth and PageHeight cells. You will use these cells later to create a title block shape that automatically sizes itself for a page.

The PageScale and DrawingScale cells are extremely useful when working with shapes for scaled drawings. We will look at the concept of scaled drawings in another module.

Working with the Page's ShapeSheet

The page sheet contains information about the page such as its width and height, ruler and grid settings, and additional optional sections. Shape formulas can refer to page sheet cells by using an intershape reference to ThePage.

Try it! Title Block Shape

1. Open a blank Visio drawing.

2. Create a rectangle shape.

3. Modify its behavior so that there is always a 1 border on its left and right sides and a 1 border at the top. The height of the rectangle should always be 2 inches. In the ShapeSheet for the rectangle set the following formulas:

Width=GUARD(ThePage!PageWidth-2in)

Height=GUARD(2in)

LocPinY=GUARD(Height)

PinY=GUARD(ThePage!PageHeight-1in)

PinX=GUARD(ThePage!PageWidth/2)

4. Resize the page and notice what happens to the shape.

Tip:

You can use the page sheet to put User-defined cells or Scratch cells that contain data global to the page. For example, you might want to define a constant that every shape on the page can reference.

Background Pages

Each Visio drawing contains at least one foreground page and may also contain one or more backgrounds. A background is a page that appears behind another page. You can create a background when you want the same shape to appear on more than one drawing page.

For example, you can place a common graphical element, such as a company logo or a border, on a background page. The element will appear on each page to which you assign the background.

Try it! Create a background page

1. Add a new page to the Visio document using Insert > Blank Page > Background Page. The Page Setup dialog will be displayed and the Page Properties tab selected.

2. Note that the page Type is set to Background. Note the default background page name. This can be changed.

Note:

All background pages in a Visio drawing will appear at the end of the page order list after all of the foreground pages. This can be seen by viewing the page tabs in the drawing window. All background pages will be at the end of the tab list of pages.

Pages Can Share Background Pages

Foreground pages in Visio can share the same background page. In the Border page example, you can create a standard border shape and place it on a border background page. You can then assign that background page to as many foreground pages in your drawing as you like.

Try it! Assign a background page to a foreground page

1. From a Visio drawing window choose Design > Page Setup > Page Properties.

2. Any Background pages that have been created will automatically be seen in the Background drop down list box on this tab. Background pages can be assigned to either Fore