Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 1 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 2 Table of Contents Table of Contents .......................................................................................................................................... 3 Visio Platform Introduction........................................................................................................................... 8 Overview ...................................................................................................................................................................9 In a Good Visio Solution ..........................................................................................................................................12 Visio Development Platform Architecture ..............................................................................................................13 Contents of a Typical Visio Solution ........................................................................................................................15 Stencils ....................................................................................................................................................................16 Creating Masters .....................................................................................................................................................17 Editing Master Properties........................................................................................................................................18 Master Shortcuts .....................................................................................................................................................20 Instancing Masters ..................................................................................................................................................22 Inheritance vs. Local Formatting .............................................................................................................................24 Identifying Local Overrides ......................................................................................................................................26 Visio File Extensions ................................................................................................................................................28 XML for Visio ...........................................................................................................................................................30 Templates ................................................................................................................................................................32 Creating a Template ................................................................................................................................................33 Add-Ons and Macros ...............................................................................................................................................34 The Drawing Explorer ..............................................................................................................................................36 Review: Visio Platform Introduction .......................................................................................................................38 Shapes and ShapeSheet Fundamentals ...................................................................................................... 40 Overview .................................................................................................................................................................41 Types of Visio Shapes ..............................................................................................................................................42 Visio Shapes as Parametric Objects .........................................................................................................................45 Visio ShapeSheet Environment ...............................................................................................................................47 Review: Shapes and ShapeSheet Fundamentals .....................................................................................................49 Defining Parametric Behavior ..................................................................................................................... 51 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 3 ShapeSheet Overview..............................................................................................................................................52 Making a Smart Arrow .............................................................................................................................................54 Making a Smart Arrow (Continued) .........................................................................................................................55 Controlling Geometry with Formulas ......................................................................................................................56 The Shape Transform Section ..................................................................................................................................58 The Geometry Section .............................................................................................................................................60 Coordinates in Visio .................................................................................................................................................61 Parent Coordinates ..................................................................................................................................................62 The Pin Secures the Shape to the Page ...................................................................................................................63 Lab 1.1: Create a Directed Graph Shape .................................................................................................................65 Referring to Other Shapes .......................................................................................................................................66 Scope of Intershape References ..............................................................................................................................68 Groups .....................................................................................................................................................................69 Controlling Resize Behavior in Groups ....................................................................................................................70 Controlling Group Behavior .....................................................................................................................................72 Controlling Group Behavior (Continued) .................................................................................................................74 Shape Operations ....................................................................................................................................................76 Creating a Multishape .............................................................................................................................................78 Lab 1.2: Multishapes and Actions ............................................................................................................................80 Review: Defining Parametric Behavior ....................................................................................................................81 Defining Text Behavior ................................................................................................................................ 83 Overview .................................................................................................................................................................84 Text Tools ................................................................................................................................................................85 Text Position ............................................................................................................................................................88 Controlling Text Position in the ShapeSheet ...........................................................................................................90 Text Rotation ...........................................................................................................................................................92 Default Text Behavior ..............................................................................................................................................93 Level Text.................................................................................................................................................................94 Gravity Text .............................................................................................................................................................95 Text Fields ................................................................................................................................................................96 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 4 Text Field Custom Formulas ....................................................................................................................................98 Resize Shapes with Formulas ................................................................................................................................100 Text Resizing Behavior ...........................................................................................................................................102 Multiple Text Blocks ..............................................................................................................................................104 Lab 1.3: Controlling Text Blocks ............................................................................................................................106 Review: Defining Text Behavior .............................................................................................................................107 Defining Page Environment ...................................................................................................................... 109 Overview ...............................................................................................................................................................110 Page Setup Dialog ..................................................................................................................................................111 Page's ShapeSheet is known as the PageSheet .....................................................................................................112 Working with the Page's ShapeSheet ....................................................................................................................114 Background Pages .................................................................................................................................................116 Pages Can Share Background Pages ......................................................................................................................117 Using Background Pages........................................................................................................................................118 Lab 1.4 Define a Background Page ........................................................................................................................119 Assigning Shapes to Layers ....................................................................................................................................120 Defining Layers ......................................................................................................................................................122 Review: Defining Page Environment .....................................................................................................................124 Defining Shape Interaction Behavior ........................................................................................................ 126 Overview ...............................................................................................................................................................127 Control Handles .....................................................................................................................................................129 Control Handle Uses ..............................................................................................................................................130 Defining a Control Handle .....................................................................................................................................131 ShapeSheet Functions ...........................................................................................................................................134 Preventing Changes to Shapes ..............................................................................................................................136 The GUARD Function .............................................................................................................................................137 The Protection Section ..........................................................................................................................................139 Named Connection Points .....................................................................................................................................141 Lab 1.5: Create a Word Balloon .............................................................................................................................143 Putting Actions on Shortcut Menus ......................................................................................................................144 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 5 Adding Smart Tags to Shapes ................................................................................................................................147 Making Shapes Respond to Events ........................................................................................................................150 Functions for Event Formulas ................................................................................................................................152 Hyperlinks ..............................................................................................................................................................154 Lab 1.6: Shape Data and Hyperlinks ......................................................................................................................156 Review: Defining Shape Interaction Behavior .......................................................................................................157 Adding Data to Shapes .............................................................................................................................. 159 Overview ...............................................................................................................................................................160 User-defined Cells .................................................................................................................................................162 Adding Shape Data to Shapes................................................................................................................................164 Defining Shape Data ..............................................................................................................................................166 Filling in Shape Data ..............................................................................................................................................169 Shape Data Sets .....................................................................................................................................................170 Using Shape Data in reports ..................................................................................................................................172 Data1, Data2, Data3 ..............................................................................................................................................175 Scratch Section ......................................................................................................................................................177 Lab 1.7: Controlling a Shape using Shape Data .....................................................................................................178 Review: Adding Data to Shapes .............................................................................................................................180 Special types of shapes ............................................................................................................................. 181 Structured Diagrams .........................................................................................................................................182 Containers .............................................................................................................................................................184 Container Shape Details ....................................................................................................................................184 Creating a visual style ........................................................................................................................................186 Creating a heading sub-shape ...........................................................................................................................188 Controlling container membership ...................................................................................................................188 Showing custom shapes in the Insert Container gallery ...................................................................................189 Using automation to get information about containers ...................................................................................189 Dropping containers with automation ..............................................................................................................192 List Shape Details ...................................................................................................................................................196 Specifying a shape to insert into lists ................................................................................................................197 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 6 Controlling list membership ..............................................................................................................................197 Callout Shapes .......................................................................................................................................................201 Using automation with Callouts ........................................................................................................................204 Summary for Special types of shapes ....................................................................................................................207 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 7 Visio Platform Introduction Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 8 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 9 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 <install folder>\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 <install folder>\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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 10 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 11 In a Good Visio Solution In a Good Visio Solution Graphical Objects (Shapes) correspond to objects in the problem domain Making the Drawing builds the Model Shape behavior encourages correct modeling and correct graphical representation Manual override is allowed for user convenience 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 cabinet’s 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 cabinet’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 12 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. Let’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 13 There are several solutions in Visio that have their own custom data import and export such as the Organization Chart and Timeline solutions. Visio’s 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 Visio’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 14 Contents of a Typical Visio Solution Contents of a Typical Visio Solution Stencils of Master Shapes Templates Add-ons and/or Macros Help Documentation Training SmartShape Symbols Automation Interface Developer Provided 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 15 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 16 Creating Masters Creating Masters Create a master from a shape in a drawing Drag a copy of the shape from a drawing to a stencil window (Ctrl, drag) Edit properties of the new master 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. 2. 3. 4. Draw a new shape, such as a red rectangle, on the drawing page. Create a new stencil by choosing from the Shapes Window More Shapes > New Stencil. Drag the rectangle shape from the drawing page into the stencil. 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 17 Editing Master Properties Editing Master Properties Name will display on Stencil Align names under icons Prompt displays shape tip Icon format When to create/ update Icon Icon size Enter Keywords to aid Search tool results How to format in case of duplicate names The Master Properties dialog displays the following properties: Name—text that appears with a master icon on a stencil Prompt—text that appears in tip balloon when you hover over the icon. Icon size—normal is the default but you can edit this. Align Master Name—left, 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 Keywords—data that is deposited in the User.visKeyword cell that is used to aid Search tool results. Match master by name on drop—if drawing already has a master of the same name, impose this master’s formatting and geometry or use the other shape’s 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 Window—the 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 18 Warning: Tip: 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. 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. 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 19 Master Shortcuts Master Shortcuts Name is "Shortcut to x" Each master shortcut can have a different action on the Drop event Set the Drop action in the Master Shortcut Properties window 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. 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… Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 20 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. 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 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 21 Instancing Masters Instancing Masters Dragging the master into a drawing window creates an instance of the master Instance created first on document stencil, then on drawing page Editing the master in a standalone stencil doesn’t affect instances in a drawing (no inheritance) You edit a master in the document stencil to make changes to instances in your drawing (inheritence) 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 <install folder>\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 doesn’t 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 22 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 23 Inheritance vs. Local Formatting Inheritance vs. Local Formatting Instances inherit from local master Changes on the page are local overrides 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. An instance can inherit many attributes from a local master—these 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 24 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 25 Identifying Local Overrides Identifying Local Overrides May not be obvious from looking at the shape Can interfere with inheritance Local overrides indicated by blue text in the ShapeSheet window Re-inheriting from the master You can see local overrides by displaying the instance’s ShapeSheet (and some dialog boxes as well). Try it! Local Overrides 1. 2. 3. 4. Select an instance with one local override, such as width. Display its ShapeSheet. Notice that a locally overridden formula is blue. 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. 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 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 26 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 27 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 selfcontained, meaning it doesn’t 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 28 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 29 XML for Visio XML for Visio The Visio XML schema contains all the data from the Visio internal model Users can access Visio XML files the same way as their peer binary format file types (VSD, VSS and VST) More detailed discussion of XML for Visio in a later module 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. 2. 3. 4. 5. 6. 7. Open a new Visio drawing. Drag 2 or 3 shapes out onto the page. From the File menu, choose Save As. Give your drawing a name, and choose to save it to your desktop. From the Save as type list, choose XML Drawing. Click the Save button, and close the drawing. Navigate to your desktop, and reopen the XML drawing file. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 30 Visio loads the file and it is displayed just as a VSD file would be. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 31 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 32 Creating a Template Walk Through Creating a Template Place some shapes into a drawing page Open one or two stencils Ensure that any new stencil files are saved and named Save the drawing as a template Close the drawing and all stencils Create a new drawing based on your template and note which windows appear Try it! Create a template 1. Open <install folder>\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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 33 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 .NET’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 34 Note: For more information on creating solutions for Visio, go to the MSDN Visio Developer Center web site at http://msdn.microsoft.com/enus/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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 35 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 36 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 37 Review: Visio Platform Introduction Review questions 1. 2. 3. 4. What is the distinction between designing with objects vs. drafting with graphic primitives? What are the components of the Visio platform? What are some reasons for using templates? 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 38 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 39 Shapes and ShapeSheet Fundamentals Shapes and ShapeSheet Fundamentals Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 40 Overview Overview Types of Visio Shapes The ShapeSheet environment Sections Cells Formulas and Values Shapes as Parametric Objects In this section we’ll explore a variety of Visio SmartShapes symbols and note fundamental differences between them. We’ll 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 41 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 shape’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 42 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 43 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 44 VisioVisio Shapes as Parametric Objects Shapes and Parametric Objects All object properties are stored in a spreadsheet called the Visio ShapeSheet Except the text The ShapeSheet view and the graphical view are two different views of the same data Visio implements all graphical interactions by changing values and formulas in the ShapeSheet Visio shapes can be customized in many different ways because there are many different properties of shapes under the developer’s 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 shape’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 45 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 46 VisioVisio ShapeSheet Environment ShapeSheet Environment View cells as “Formulas" or “Values" Edit the content of cells View sections Reduce section to just title bar view Insert sections Cannot rearrange sections 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 47 Unlike other spreadsheet applications, Visio’s 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, userdefined cells, controls, and connection points. Each of these behaviors is created by first adding the appropriate section to the shape’s 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”. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 48 Review: Shapes and ShapeSheet Fundamentals Summary: Shapes and ShapeSheet Fundamentals Types of Visio Shapes The ShapeSheet environment Sections Cells Formulas and Values Shapes as Parametric Objects 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? Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 49 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 50 Defining Parametric Behavior Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 51 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 shape’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 52 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 53 Making a Smart Arrow Making a Smart Arrow With default formulas, the arrowhead distorts 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 54 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 55 Controlling Geometry with Formulas Controlling Geometry with Formulas So far, we have created an arrow with smart width, but not smart height To get smart height, make the width of the arrow head proportional to its height Stretch the arrow in height and observe what happens. The smart arrow we’ve 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 arrowhead’s 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 arrow’s 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” Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 56 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 57 The Shape Transform Section The Shape Transform section determines a shape’s 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 shape’s parent (group or page) PinY Y ordinate of Pin relative to the shape’s 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 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 58 The pin is expressed in the coordinate system of the shape’s parent. The local pin is expressed in the coordinate system of the shape. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 59 The Geometry Section A shape’s 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 shape’s width and height. You can control a shape’s vertices by writing your own formulas in the shape’s 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 shape’s Width and Height. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 60 Coordinates in Visio To control a shape’s 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 page’s width. The positive Y direction corresponds to the page’s height. The origin remains the same, even if the ruler view of the page has been changed. Note: 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 shape’s origin is in the lower left corner of the shape’s alignment box. The positive X direction corresponds to a shape’s width and the positive Y direction corresponds to a shape’s height. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 61 Parent Coordinates The parent coordinate system of the shape is the local coordinate system of the shape’s 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 shape’s 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 group’s origin being in its lower left corner. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 62 The Pin Secures the Shape to the Page Here’s 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 shape’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 63 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 <install folder>\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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 64 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 shape’s 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 shape’s size. Try different units as well and note that the default units used by Visio are inches when no unit is entered Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 65 Referring to Other Shapes A shape’s 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 shape’s name by displaying the Shape Name dialog box, or by looking at the title bar for the ShapeSheet window. The Shape Name dialog is accessed from the Developer tab. Note: 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 66 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 shape’s id value.. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 67 Scope of Intershape References Whether you can refer to a shape by name, and the exact syntax you’ll use, depends on the location and scope of the shape you’re 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 shape’s 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, Sleeve’s Width formula must be = Sheet.3!Width - Hand!Width Because Arm is Sleeve’s parent, Sleeve cannot refer to Arm by any name other than its Sheet.ID name. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 68 Groups Groups Members of a group retain their identity as separate shapes Retain their ShapeSheets and individual formatting Can be added or removed individually Ungroup at any time Intershape formula references between parent and child shapes for more complex shape behavior 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 group’s coordinate system because the group is now the parent. When you ungroup, the process is reversed and the group’s 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 group’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 69 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 group’s coordinate system. If a member shape represents an object with fixed physical dimensions—for example, a sink in a kitchen countertop—you 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 70 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 71 Controlling Group Behavior When Snap to member shapes is selected, you can snap and glue to member shapes within the group. Note: If you aren’t 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 72 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 73 Controlling Group Behavior (Continued) Controlling Group Behavior (Continued) Selection order Group only Group first Members first Group data Hide Behind member shapes In front of member shapes 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 Visio’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 74 Manipulating Group data selections sets the group display order for text or shapes in a group. Selecting Hide will hide the group’s components except for connection points and control handles. Behind member shapes specifies to place the group’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 75 Shape Operations Shape Operations Union, Combine, Fragment, Intersect, Subtract Create new and more complex shapes Destroys original shapes including smart formulas Selection order influences result Use for multiple shapes that have the same text, line, and fill formats Smaller and faster than groups Use groups for complex shapes with multiple text, line and fill formats 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 76 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 77 Creating a Multishape Creating a Multishape A multishape provides multiple shapes in a single master Visio example: “Flowchart shapes” master Use Combine to create one Geometry section for each component Can use Group shape but more difficult Use SETF( ) formulas to toggle Geometry NoShow cells Put actions on shortcut menu 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. 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: Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 78 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 79 Lab 1.2: Multishapes and Actions Lab 2.2: Multishapes and Actions Create a chair shape with arms Add two options to its shortcut menu to “Show Arms” or “Hide Arms” Display or hide the geometry sections accordingly Challenge Display only “Show” or “Hide” in the right-mouse menu, depending on current status of the shape 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 80 Review: Defining Parametric Behavior Review questions 1. 2. 3. 4. 5. What cells determine a shape’s position? What type of coordinate system is used in Visio? What is an Intershape reference? Can you think of examples where they might be useful? What would the formula in a group member shape’s Width cell refer to? 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? Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 81 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 group’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 82 Defining Text Behavior Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 83 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 84 Text Tools Text ToolBar Items Text Tool A Text Block Tool 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. 2. 3. 4. Create some text using the Text tool. Select the shape and view its ShapeSheet Note that it has a Geometry section. 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. That’s all it really is! Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 85 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 shape’s text block, click inside the center of the shape or on the green border, and then drag. To size a shape’s 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 shape’s text block. The text block has its own coordinate system independent of the shape’s geometry. Try it! Text Behavior Basics I 1. Open <install folder>\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. Microsoft Visio 2010 Developer Training © 2010 Microsoft Corporation. All rights reserved. Volume 1: Shapes and ShapeSheet Fundamentals 86 4. The text coordinate system is positioned relative to the shape’s local pin. By default it is the same size as the shape’s alignment box. You can also control the text behavior from the ShapeSheet. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 87 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 88 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 shape’s appearance. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 89 Controlling Text Position in the ShapeSheet The Text Transform section of the ShapeSheet contains formulas and values for the text block’s 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 shape’s Width and Height. The default formulas in TxtLocPinX and TxtLocPinY refer to TxtWidth and TxtHeight. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 90 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 91 Text Rotation In addition to deciding where to place text, you’ll 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 shape’s text independently of the shape itself. The angle of the text (TxtAngle) is relative to the shape’s rotation, so a TxtAngle value greater than 0.0 adds to the shape’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 92 Default Text Behavior Default Text Behavior STOP TxtAngle=0 deg. Text rotates with the shape 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 shape’s angle (TxtAngle=0 deg). Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 93 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 shape’s 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-rotation’s 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)”. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 94 Gravity Text Gravity Text Set TxtAngle=Gravity(Angle,90 deg.,270 deg.) ABC C AB C AB ABC 180 deg C AB ABC 0 deg 180 deg C AB Default ABC C AB C AB ABC 0 deg C AB C AB ABC 270 deg ABC 90 deg 90 deg ABC 270 deg Gravity 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 95 Text Fields A text block can have text fields, which are placeholders to display drawing or shape information. Try it! Text Fields 1. 2. 3. 4. Instance the 2-D arrow shape and ensure the shape is selected. From the Visio ribbon, choose Insert tab > Field. Look at the various options in the Insert Field dialog box. Insert a field to make the arrow display today’s 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.. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 96 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 you’ve designed a text block to display field information, you will probably want to deny the user textediting privileges. You can protect against the user changing these fields by locking the shape’s text. Set the LockTextEdit cell in the Protection section of the ShapeSheet to 1 or True to prevent a user from tampering with a shape’s text. We will look at shape protection issues in more detail in later in this module. Note: 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 97 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” Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 98 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 99 Resize Shapes with Formulas Visio allows the text block to grow beyond the height of the shape. Instead of having the user correct the shape’s 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 <install folder>\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 shape’s 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)) TheText—refers to all the text of the shape Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 100 Width—width allowed (the width to break lines to) Now the Word Balloon will tightly enclose any amount of text entered. 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 101 Text Text Resizing Behavior Resizing Behavior Visio default behavior maintains original font size when the shape is resized In many real-world objects the shape and its text should resize proportionately SCHOOL ZONE SCHOOL ZONE 15 M.P.H. 15 M.P.H. Char.Size = (Current height/Orig height) * (Orig font size) Another important question is whether the text and shape sizes should correspond. Visio’s 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 shape’s dimensions. To resize the font you can apply a conversion ratio that represents how the shape’s 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 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 102 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 103 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. The parent shape (group shape) accepts the default text for the group. Note: Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 104 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. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. Draw a rectangle and use the Corner Rounding tool to make it look accurate. Using the Text Tool, add a text block for the “School Zone” text, and format it accordingly. Open its ShapeSheet and add a User-defined cell called FontSize. Enter in the font size conversion ratio. Set the Char.Size cell to refer to User.FontSize. Make sure to Guard this formula. Copy the “School Zone” text block and change the text to “MPH”. Position the text blocks, and group them with the sign shape. Select the sign shape again and type in the speed limit. Format it accordingly. Remember, you are working with the group’s text block here. Repeat steps 3, 4 and 5 for the group shape. In the Protection section for the group, set LockAspect to 1. 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. Test your smart text behavior by changing the size of your shape. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 105 Lab 1.3: Controlling Text Blocks Lab 2.4: Controlling Text Blocks Create the speed limit sign shape so that the text resizes when the shape resizes The speed limit number should be the default text block for the shape The sign’s Width should grow in proportion to its Height 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 106 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. 2. 3. 4. How can the text block be changed from the user interface? How do you display the Text Transform section in the ShapeSheet? Can a shape have multiple text fields? 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? Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 107 Answers 1. 2. 3. 4. 5. 6. Use the Text Block tool. Use Insert > Section or just move the text block with the Text Block tool. Yes TEXTWIDTH and TEXTHEIGHT Easier to position and format individual text blocks. Use the Text tool to create additional text block. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 108 Defining Page Environment Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 109 Overview In Visio, the user has control over drawing page size and scale. This information is maintained as part of the page’s 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 page’s ShapeSheet. It has a Page Properties section, which is similar to the shape’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 110 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. Printer setup control has its own tab called Print Setup. Note: Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 111 Page's ShapeSheet is known as the PageSheet Information about a page can be viewed in the page’s ShapeSheet. The page’s 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 112 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 113 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 114 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 115 Background Pages Background Pages Any page can be a background page Foreground Background Background Background Pages can be stacked Objects show through 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. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 116 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 Foreground pages or to other Background pages. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 117 UsingUsing Background Pages Background Pages Show same shapes on multiple pages Saves space in drawing file Can’t select or edit background page shapes from foreground pages Pages do not have to be the same size or scale, but work best if they are Background pages show the same shapes on multiple pages. Advantages to background pages include saving space in you drawing file as well as not being able to edit background page shapes from foreground pages. Background pages do not have to be the same size or the same scale as the foreground pages they are assigned to, but work best if they are. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 118 Lab 1.4 Define a Background Page Lab 1.2: Define a Background Page Define a page as a background page Place some objects on the page Reference the background page from multiple foreground pages Points to Consider 1. A background page, when created, adopts the page size and scale of the page that is visible. 2. After creating a background page, you must go back and assign that background to each foreground page. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 119 Assigning Shapes to Layers Assigning Shapes to Layers A layer is a named category of shapes in a drawing Think “Class”, not “Glass” A shape can be assigned to more than one layer Layers are scoped to the page Work with Layer Properties Number, Color, Transparency Lock, Print, Visible, Active Snap, Glue Shapes can be assigned to layers as a way to categorize information in a drawing. In many drawing programs, the term layer refers to the stacking order of objects on the page. In Visio, a layer is primarily a means of organizing shapes into categories, and only secondarily a visual mechanism. Note: Visio layers are independent of stacking order. Think of a Visio layer as a class of shapes rather than a glass layer such as a foreground page. Because layers are categories, a shape can be assigned to multiple layers. For example, in your space plan, you might want to assign cubicles to a furniture layer, but also to a semi-permanent layer. It might be useful to see the space plan in each of those views—walls only, walls and semi-permanent furniture, walls and cubicles, and other movable pieces. Note: What happens if the two layers have conflicting property settings, for example if one was visible and one was hidden? The most liberal setting wins. If any of the layers a shape is assigned to is visible, that shape is visible. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 120 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 121 Defining Layers Masters can add layers to a drawing. If you instance a master or copy a shape with layer membership data onto a page, that page inherits the shape’s layers. Here’s how to define a layer and assign a shape to it in Visio. Try it! Creating Layers 1. From your student CD, open <install folder>\Vol1\S5 Defining Page Environment\Creating Layers.vsd, and a new blank stencil. 2. From the Home tab, choose Layers > Layer Properties to open the dialog box. Try out some of the effects of a few of the Layer Properties such as Lock, Visible and Color and Transparency. 3. Draw a rectangle shape on the page, and change its line weight to 17. Type in the text “My Layer”. 4. Drag a copy of the shape to the stencil. Name the master My Layer. Open the master, select it, and choose Home > Layers > Assign to Layers. Note: In the Layer dialog for the master, the layers previously defined on your drawing page do not appear because layers are scoped to that page. Each master has its own drawing page, and therefore its own defined layers. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 122 5. Create a new layer called My Layer, and assign your master to it. 6. From the same edit master window, choose Home > Layer > Layer Properties, and give your new layer the color of dark green. Update the master. 7. Drag the My Layer shape onto the page, and open the page’s Layer Properties dialog. The layer that was created within the master shape’s drawing page, has now been added to your drawing page. 8. Finally, on your drawing page, make the Beta layer Active, and draw some new shapes on the page. Newly drawn shapes or master shapes that do not have their own predefined layer, will automatically be assigned to the page’s Active layer. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 123 Review: Defining Page Environment Summary: Defining Page Environment I Setting up the page environment Page information in the ShapeSheet Page Properties section Accessing page information Utilizing background pages Now that you have started working with the Visio page environment, here are some questions relating to the material just covered. Review Questions 1. What dialog is used to set up the page environment, such as size and scale? 2. What information does the page’s ShapeSheet (also called the PageSheet) contain? 3. How is the Page Properties section of the PageSheet like the Shape Transform section of a shape's ShapeSheet? 4. What happens if the layers have conflicting property settings? 5. What are two ways to add a layer to a drawing page? Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 124 Answers 1. 2. 3. 4. Page Setup dialog from the Design tab. Page Properties, layout information, Shape Data, ruler and grid settings. It controls the page’s width and height. The most liberal setting will win. For example, if a shape is on two layers, and one is locked, the shape will still be selectable. 5. Assign the master to a layer before it is dropped. Select the shape and choose Home > Layers > Layer. Set the active property of a layer before adding a shape. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 125 Defining Shape Interaction Behavior Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 126 Overview There are many ways to modify the behavior of a shape. In this section you will explore some of the basic techniques of controlling shape behaviors. Objectives Adding controls and connection points. Using functions in the ShapeSheet to affect the shape’s behavior. Lock down some behaviors on a shape to prevent some types of user interaction such as locking the shape’s size or text. These are found in the Protection section. Use functions in the ShapeSheet to affect shape behavior. One function (Guard) can be used to protect the contents of a ShapeSheet cell from changes initiated through the user interface. Put an Action on a shortcut menu or adding a smart tag to a shape to providing additional shape interaction behavior. Add formulas to Event cells in the ShapeSheet to react to common events such as shape moved or text changed. Add hyperlinks to provide links to additional information about a shape, a page, a document, or a website. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 127 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 128 Control Handles A control handle is a special shape feature that can be added to any shape and may be used to adjust multiple aspects of that shape. A control handle appears as a yellow diamond on a shape that you interact with by left-clicking and dragging it. Control handles are programmed through the ShapeSheet to modify various aspects of a shape. For example, a control handle can be placed on a square and be programmed to round the corners of the square when moved. Control handles can affect text behaviors as well, such as placement and resizing behaviors. In addition to enhancing shape and text behaviors, control handles can also glue to other shapes. Control handles have tips that explain the function of the control handle. A control handle’s tip can be viewed by hovering the cursor over the control handle momentarily. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 129 Control Handle Uses One way to control shape behavior and still provide users with great flexibility is to add control handles to a shape. Control handles are small yellow diamonds that users can select and move. A shape responds to changes in the control handle’s position through the association of other ShapeSheet cells to this position. The real strength of control handles is that they let you take advantage of user input when designing shape behavior. Many of the SmartShapes symbols provided with Visio use control handles to give shapes this kind of enhanced behavior. This slide shows some examples. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 130 Defining a Control Handle Defining a Control Handle Initial handle position (Controls X, Y) Anchor point in local coordinates for rubber band feedback during dynamics (XDynamics, YDynamics) How control should behave when the handle is moved (XBehavior, YBehavior) Whether handle can be glued to other shapes (CanGlue) Provide helpful control behavioral information (Tip) Turns on or off the display of all control handles for a shape (Miscellaneous.NoCtlHandles ) Recalculation of the alignment box whenever a control handle is moved (Miscellaneous.UpdateAlignBox) Here is a description of the cells that effect control handles. ShapeSheet Cells Description Controls.X, Controls.Y Define the handle’s position. Controls.XDynamics, YDynamics Define anchor point in local coordinates for rubber band feedback during dynamics. Controls.XBehavior, YBehavior Define how the handle moves when the shape is stretched. Controls.CanGlue Defines whether the control handle can be glued to other shapes. Controls.Tip Displays a “tip” when the mouse is placed over the control. A control tip ideally should be no more than four words. Miscellaneous.NoCtlHandles Turns on or off the display of all control handles for a Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 131 shape Miscellaneous.UpdateAlignBoxControls recalculation of the alignment box whenever a control handle is moved. Note: Tip: Tip: Controls.XDynamics and Controls.YDynamics are still available, but somewhat obsolete. You must turn off Enable Live Dynamics to see the effect of these cells. Go to Tools > Options > General tab to deselect Enable Live Dynamics. For control Tips, it is recommended that you use headline style capitalization–that is, capitalize the first letter of each word. Set Geometry vertex formulas to refer to Controls.X, Controls.Y cells to tie shape geometry to a control handle. Try it! Create a triangle with a control handle that moves its apex 1. Open a blank drawing. 2. Create a triangle and insert a Controls section into the triangle’s ShapeSheet. 3. Find the vertex in the Geometry section that corresponds to the triangle’s apex. From this vertex, reference the Controls X and Y cells as follows: a. X=Controls.Row_1 b. Y=Controls.Row_1.Y Now when the control is moved, the position of the apex moves with it. 4. Set X and Y behavior cells so you can pull the apex laterally but not vertically. See Help. a. XBehavior=0 b. YBehavior=1 5. Add a Control Tip “Move the Apex” to your control handle. Experiment with other formulas in the Tip cell. Try setting the tip cell to: =“Width=”&Width Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 132 If the control handle moves part of the shape, you can update the alignment box to enclose that part of the shape. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 133 ShapeSheet Functions Visio has many common and special-purpose functions you can use in formulas. Several are listed on the slide. See the help file for a complete list of all functions. Intellisense is a feature of the ShapeSheet. Editing any cell automatically causes functions to be shown to the user as you type. Try it! Create a rectangle that is a minimum of 1-inch high 1. Using the Rectangle tool, create a rectangle of any reasonable size. 2. Set the Y formulas for the top vertices to. = MAX(Height, 1 in). Note that as you begin to type, Intellisense presents function names to you. The above formula defines the shape’s height to be the greater of 1 inch or the Height from the Shape Transform section. 3. Change the height of the shape to see the formula in action. Try it! Set the color of a shape based on its size. 1. Create a rectangle and open its ShapeSheet. 2. Set the Fillforegnd cell of the Fill Format section to =IF(Width<2in,2,3) by typing into the Fillforegnd cell. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 134 3. Modify the width of this shape. Its color will change to red if it is smaller than 2 inches wide, otherwise its color will be set to green. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 135 Preventing Changes to Shapes Preventing Changes to Shapes We've seen that actions in the drawing page affect the ShapeSheet These actions can replace your formulas with Visio’s defaults Lock shapes to prevent certain actions Guard formulas to prevent Visio from replacing them Most actions in the drawing page affect the ShapeSheet. For example: Stretching a shape updates its Width and Height formulas in the Shape Transform section. Flipping a shape updates its FlipX and FlipY formulas. If you’ve created smart formulas, you’ll want to protect them by using one of the following methods: You can set constraints on shape behavior to protect or “lock” the shape against certain actions on the drawing page. You can use the GUARD() function to prevent Visio from overwriting your formulas. Try it! Guarding Formulas 1. 2. 3. 4. Create a rectangle shape and set its Width cell to “=Height*0.5” Drag the resize handle to resize the shape’s width. The Width formula is reset. Set the original shape’s Width cell to “=GUARD(Height*0.5)” Drag the resize handle again and note how the formula is now protected. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 136 The GUARD Function A GUARD() function is entered into the ShapeSheet as part of a formula. Guard protects the entire formula, not just part of it. No visual clues are provided to the user. Options to change ShapeSheet cells will still be available through the menus. GUARD() doesn’t protect a formula if the cell or section is deleted or overwritten. Note: Try it! Guard() 1. Create a new drawing using File > New > Maps and Floor Plans > Office Layout (US units) 2. This is a good example of a scaled drawing. In this case, the scale is Architectural, 1/2 inches = 1 foot. 3. Open the stencil <installfolder>\Demos\Vol1\S6 Defining Shape Interaction Behavior\Interaction Shapes.vss> and instance the Grand piano shape onto your page. 4. Open the ShapeSheet and observe the FlipX and FlipY cells in the Shape Transform section. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 137 The grand piano shape is guarded against flipping, because in a real grand piano the long strings (low notes) are always on the left. The user might accidentally flip the shape to try to orient it a certain way in a layout diagram. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 138 The Protection Section Here are some facts about the Protection section in the ShapeSheet. Set a cell’s value to non-zero to enable protection, or to 0 to disable it. Some options are also available in the Protection dialog box. Setting values in the Protection section provides users with visual clues about what they cannot do. However this action cannot prevent ShapeSheet changes or a user from turning off the lock. Try it! Protection Section 1. Create a new drawing using File > New > Maps and Floor Plans > Office Layout (US units) This is a good example of a scaled drawing. In this case, the scale is Architectural, 1/2 inches = 1 foot. 2. Open the stencil <installfolder>\Demos\Vol1\S6 Defining Shape Interaction Behavior\Interaction Shapes.vss and instance the Keyboard shape onto your page. 3. Stretch the shape to see what LockAspect does. 4. Instance the Table shape from the Office Furniture stencil. Choose Developer > Protection and protect the shape’s Width and Height. Microsoft Visio 2010 Developer Training © 2010 Microsoft Corporation. All rights reserved. Volume 1: Shapes and ShapeSheet Fundamentals 139 5. Notice that the handles are now gray. By setting the LockWidth and LockHeight cells for this shape, the user is unable to change its size. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 140 Named Connection Points The Connection Point rows are not named by default, however, you can easily rename them to create a more meaningful reference for the X and Y cell values (local coordinates) of the row. Once one row is named, Visio will automatically name the rest Connections.Row_1, Connections.Row_2 and so on. Connection points have a type (Type/C cell). The default type for a connection point is to be inward facing. This allows the connection to accept incoming connectors, such as the end point of a 1-D shape. For example, directed connections do not apply to flowchart shapes where lines connect to boxes. However, an outward-pointing connection point can glue to an inward-pointing connection point. The angle of the connector (Dir/A, Dir/B cells) is used to orient the two shapes. The X and Y cells determine the component for the required alignment vector of a matching connection point. Directed connections apply to shapes that need to snap, glue, or orient to each other. For example, two 2-D shapes can be connected together like a jigsaw puzzle. The “D” cell is a scratch cell you can use for entering and testing formulas. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 141 Try it! Naming Connection Points 1. 2. 3. 4. From the File menu, choose New > Flowchart > Basic Flowchart (US units) Drag over an instance of the Document shape and display its ShapeSheet window. In the Connection Points section, note that the rows are not named. Find the Connections Row corresponding to the Connection Point on the left side of the Shape and type the name LeftSide into that row name cell. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 142 Lab 1.5: Create a Word Balloon Points to Consider 1. The geometry of the mouthpiece needs to reside outside of the rectangular portion of the balloon. This is tied to the alignment box of the shape. 2. If you use a basic rectangle as the starting shape, additional vertices must be added to the shape. Select the line tool. Press the control key and select the shape along the bottom edge where you want extra vertices to be added. This will enable you to create and drag out the balloon mouthpiece. Double-click the shape to turn off display of the control. Challenge: Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 143 Putting Actions on Shortcut Menus When the user right-clicks on a shape or drawing page, a shortcut menu appears that includes commands that apply to that context. You can add commands to a shortcut menu in a number of ways. Try it! Adding an Action to a Shortcut Menu 1. 2. 3. 4. 5. 6. 7. Open a new drawing. Add a second page. Navigate to Page 1. Create a rectangle on Page 1 and open its ShapeSheet window. Insert an Actions section. Add the formula =GOTOPAGE(“Page-2”), and fill in the menu string. In the PageSheet for Page 2, add an Actions section with the formula =GOTOPAGE(“Page1”), and fill in the menu string. 8. Right-click on the rectangle on Page 1, and “Go to Page 2”. 9. Right-click on the drawing page on Page 2, and “Go to Page 1”, and so on. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 144 Note: The fact that the page can also have a shortcut menu provides a way for your templates to have some document level Action functionality. In a later section, you will learn how to run a macro from an Action cell. Use the Checked and Disabled cells in the action row to control these properties of the menu. Normally, action menus are listed in the order created and at the top of the menu. To place a menu at the bottom of the menu, prefix its menu string with the % (percent) character. To create a separator bar, prefix the menu string with the _ (underscore) character or create a separate row and set the Menu cell to “_”, or set the BeginGroup cell for the menu to True. The following are additional cells in the Action section: BeginGroup – indicates whether a separator is inserted into the menu above this action. ButtonFace – identifies the icon that appears next to an item on a shortcut or smart tag menu. Invisible – Indicates whether the action is visible on the smart tag or shortcut menu. ReadOnly – Controls whether the action on a smart tag or shortcut menu is read-only. When an action is read-only it appears on the smart tag or short cut menu, but you cannot select it. It is not dimmed as when disabled, but it does appear on a colored background. SortKey – a number that determines the order of actions that appear on a shortcut or smart tag menu. TagName – Contains the name of the smart tag that this action is associated with. FlyoutChild – Used to create flyout right click menus Create a cascading menu A FlyoutChild cell allows the creation of cascading menus as a right mouse action on a shape, although only one level deep. As an example, observe the shape below. A right click on the shape shows the cascading menu Fill Color followed by the options Red, Green, and Blue. How this is set up is shown in the ShapeSheet below the shape image. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 145 The FlyoutChild cell is set to True for each of the child menus. The Action cell of the top menu Fill Color has no action. The Action cell for each of the child options has a formula which is evaluated when that menu is chosen. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 146 Adding Smart Tags to Shapes Visio enables the creation of Smart Tags on a shape or on the drawing page. Smart Tags can be used to make important shape actions and settings more discoverable. Include smart tags on shapes to display a drop-down menu when a user hovers over a smart tag button. The Smart Tags section controls the appearance and position of smart tags in the drawing. The Smart Tags section works together with the Actions section (where the menu items that appear on a Smart Tag menu are defined). Use the TagName cell to associate each smart tag with a row or rows in the Actions section. A single shape or page can contain multiple smart tags. Note: If a smart tag has no matching actions, the smart tag button appears and disappears as defined, but its menu is blank. Try it! Adding a Smart Tag to a shape 1. Start with any shape on the drawing page. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 147 2. 3. 4. 5. Open the ShapeSheet for the shape. Insert a Smart Tags section. Insert an Actions section. Set the TagName in the first row of the Action and the TagName in the first row of the Smart Tag section to the same value, e.g., “Tag1”. This will link the two together. 6. Set the following values in the first row of the Actions section Cell Action Menu TagName Value SETF(GetRef(Fillforegnd),2) “Set color to red” “Tag1” 7. Set the following values in the first row of the Smart Tags section Cell X Y TagName DisplayMode Description Value Width/2 Height/2 “Tag1” 1 “Set the shape’s color” The following are cells of the Smart Tags section: X – The x-coordinate position in the shape's local coordinates around which the smart tag button is placed. Y – The y-coordinate position in the shape's local coordinates around which the smart tag button is placed. TagName - Name of the smart tag that is used as a key to associate the smart tag with its actions. X Justify – The x-offset of the smart tag button relative to the point defined by the X and Y cells. o 0 – Left justified o 1 – Centered o 2 – Right justified Y Justify – The y-offset of the smart tag button relative to the point defined by the X and Y cells. o 0 – Top justified o 1 – Centered Microsoft Visio 2010 Developer Training © 2010 Microsoft Corporation. All rights reserved. Volume 1: Shapes and ShapeSheet Fundamentals 148 o 2 – Bottom justified DisplayMode – determines when the smart tag is displayed o 0 – When the mouse is paused over the tag o 1 – When the shape is selected o 2 - Always Buttonface – Contains the ID of the button face image that appears on the smart tag button. Description – appears as a tool tip when the user pauses the mouse over the. Disabled – Indicates whether the smart tag appears in the drawing window. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 149 Making Shapes Respond to Events You can define how a shape responds to particular user actions on the drawing page by writing an event formula. You can trigger an event formula when the user edits a shape’s text, moves or rotates the shape, double-clicks the shape, or instances a master shape or shapes. For example, an event formula might open a file when the user double-clicks the shape, or run an addon or macro when the user drags a master into a drawing. There are a couple of things to keep in mind about event formulas: An event formula is evaluated when the event occurs, rather than when you enter the formula or when the rest of the ShapeSheet is evaluated. This means that the value displayed in an Events cell may appear to be out of date or inconsistent with the cell’s formula until the event actually occurs. The order of evaluation and the number of times an event is evaluated are unpredictable. For example, if a shape’s text is formatted and the shape is resized (such as a shape that resizes itself if its text grows or shrinks), the order in which these events trigger evaluation of formulas is unknown. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 150 Note: EventDrop will only evaluate if a single shape is dropped. To detect when multiple shapes have been dropped at once, use EventMultiDrop. The Double-Click event can also be accessed and formatted from the Developer > Behavior dialog. Here you can set event actions including open the ShapeSheet, Display Help, Run a Visio registered macro or Go to a page in the document. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 151 Functions for Event Formulas Functions for Event Formulas OPEN“XXX”( ) functions GOTOPAGE( ) SETF( ) RUNADDON( ) CALLTHIS( ) DOOLEVERB() PLAYSOUND( ) DEFAULTEVENT( ) BOUND() Visio has several functions that are designed especially for event formulas. Visio function Event OPENFILE, OPENGROUPWIN, OPENPAGE, OPENSHEETWIN, OPENTEXTWIN GOTOPAGE Opens a file, group window, page, sheet window, or text edit window. SETF RUNADDON, RUNADDONWARGS CALLTHIS DOOLEVERB PLAYSOUND Displays a different page in the active window. Sets a cell’s formula. Runs an add-on, plain or with arguments. Can be the name of a VBA procedure, a macro or a command that the VBA window can execute. Calls a procedure in a VBA project, locally or in a different open document, and passes a reference to the shape that made the call. Executes a command for a linked or embedded object so that it can be edited. Plays a .wav file or system sound (on a Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 152 DEFAULTEVENT system with sound). Default behavior for shape. Use this in a conditional expression, to perform some action if the condition is true, or revert to default behavior if it is not. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 153 Hyperlinks Hyperlinks can be added to a shape or drawing page to create a link to another drawing page, another file, or a Web site. Hyperlink section cells Description Description Address A descriptive text string for a hyperlink. Specifies a URL address, DOS file name, or UNC to which to jump. Specifies a location within a target document to link to. Represents a string that passes information to be used in resolving a URL, such as the coordinates of an image map. The name of a frame to target when the Visio application is open as an ActiveX® document in an ActiveX container. The hyperlinks on a shortcut menu appear on the menu sorted from lowest to highest, with lower numbers appearing at the top of the menu. If two hyperlink rows have the same SortKey cell value, the order is determined by physical row order. The default is 0 (zero). Specifies whether to open the hyperlink in a new window. SubAddress ExtraInfo Frame SortKey NewWindow Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 154 Default Invisible Determines the default hyperlink for a shape or page. Set the value of this cell to TRUE to set a hyperlink as the default. You can also select the shape, choose Insert > Hyperlinks, select a hyperlink, and then click Default. The default hyperlink appears in bold text. If set to TRUE, the hyperlink does not appear as a menu item on the shortcut menu. Otherwise, the hyperlink does appear as a menu item on the shortcut menu (the default). The HYPERLINK function navigates to the specified address, which can be a DOS, UNC, or URL path. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 155 Lab 1.6: Shape Data and Hyperlinks Points to Consider 1. The Basic Laptop shape can be found on your student CD in the <install folder>\Demos\Vol1\S6 Defining Shape Interaction Behavior\Interaction Shapes.vss stencil. 2. Make a conscious design decision between a fixed or variable list for Prop.Manufacturer. 3. The formula in the drop event includes the DOCMD function. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 156 Review: Defining Shape Interaction Behavior Review Questions 1. 2. 3. 4. 5. 6. 7. How are control handles on shapes useful? How is a control handle added to a shape? How does one find Help information about functions? What are two ways to protect information in shapes. How would you create a separator bar between two Action menu items? What is the difference between RUNADDON and CALLTHIS? Name three things a Hyperlink can link to. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 157 Answers 1. Control handles can be used for many purposes such as moving geometry, moving text, resizing a portion of a shape, etc. 2. Add a row to the Controls section in the ShapeSheet. 3. Complete documentation for developers is available in the Visio SDK. 4. Use the GUARD() function to protect and individual cell. Use the Protection section to protect specific behaviors. 5. Set the BeginGroup cell for that menu or precede the menu name with an underscore character (“_”). 6. RUNADDON can start any addin in Visio’s Addins collection or call a macro. CALLTHIS is for calling a macro and passing a reference to the shape that made the call. 7. A Visio drawing page in the current drawing, another file, or a web URL. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 158 Adding Data to Shapes Adding Data to Shapes Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 159 Overview During the discussion comparing drawings and models, you learned that models contain more than just the drawing data. They contain information that more fully describes the drawing, such as manufacturer and cost data for network equipment, or references to supporting documentation for process flow diagrams. This section will cover various ways to add data to shapes and pages that help turn an ordinary drawing into a rich repository of model data. There are several ways to store additional data into a shape. Shape data fields provide more flexibility in storing and displaying data than do Userdefined cells. For example, the type of data can be described in a shape data field property. Shape data fields typically hold data that can be modified by the end user. The User-defined section provides cells for storing small amounts of data like reference formulas. These cells are typically used by shape developers to hold information about the shape that is not usually seen by the end user. For additional data storage, there are three fields—Data 1, Data 2, Data 3 which are still available for bulk storage, but are generally considered obsolete. These can be accessed through the Developer > Shape Name dialog. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 160 Similarly, the Scratch section is available to hold shape formulas and data, but this is also considered obsolete and superseded by the User section of the ShapeSheet. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 161 User-defined Cells Most ShapeSheet cells have a predefined purpose. However, sometimes you need to do an intermediate calculation, either to simplify a complex formula or to optimize several formulas. User-defined cells can hold anything you want: Intermediate calculations Constants Parameters for a shape User-defined cells can also have meaningful names. This makes intercell references simpler to implement and easier to read. Note: The visKeywords user cell contains shape specific data that is used by the Search tool. The visVersion user cell tells you in what version of Visio the shape was created. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 162 Try it! User-defined Cells 1. 2. 3. 4. Create a shape and open its ShapeSheet. Right-click inside the ShapeSheet and select Insert Section … Select User-defined cells. Modify the existing cell in User-defined cells: a. Name the cell WatchHeight. b. Set User.WatchHeight=IF(Height<1in,SETF(GetRef(Height),1in),0) This ensures that the height of the shape never becomes less than 1 inch. This same problem was solved another way earlier by using the MAX function. Note: Try it! User-defined Cells II 1. From the stencil <install folder>\Demos\Vol1\S7 Adding Data to Shapes\Adding Data Shapes.vss, instance the shape Double Arrow 2. 2. Open its ShapeSheet, and look at its User.WatchHeight formula. This User-defined cell prevents the arrowheads from overlapping when the width becomes smaller than the height. Tip: You can also put formulas into the User-defined section’s Prompt cell. This enables you to double the number of formulas you can put in one User-defined row. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 163 Adding Shape Data to Shapes Often shapes have related data, and users may want to store that data with the shapes in Visio. You can do this by using Shape Data. In prior versions of Visio you could create Custom Properties for objects, and use them for storing information about the class of shape, or the specific instance of a master. With Visio 2007 this functionality is essentially unchanged, but has been renamed to Shape Data to better reflect the method of use and to align with the Data menu functions. Objects which can contain Shape Data include: Mastered Shapes Groups * Items created using Drawing tools The Drawing Page Note: While Shape Data can be created for a group, remember that the ShapeSheet of a group is deleted when a group of items is Ungrouped. Since Shape Data is stored in the ShapeSheet, this means that the fields and the data they contained will all be removed from the drawing. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 164 For ease of reference, the term ‘shape’ will be used throughout these discussions, and will include all item types listed above. Shape Data can be created manually or programmatically, on a shape by shape basis, or for a group of shapes at the same time. You can also create and apply Shape Data Sets, to be applied to one/many other shapes. Starting with Visio 2007, users are able to create Shape Data through the Link Data to Shapes wizard, which will be seen in a later lesson. In addition, Shape Data is leveraged in several legacy solutions, such as the Organization Chart. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 165 Defining Shape Data You add Shape Data to a shape in the Shape Data section of the ShapeSheet, or via the Define Shape Data dialog. Like the rows in the User-defined section, rows in the Shape Data section can be named. Use the row name to refer to shape data cells. The Value cell can be referred to using the syntax Prop.MyProperty. If you want to refer to another cell in the row, append the cell name to the reference. For example, Prop.OWNER.Prompt will reference the OWNER’s Prompt cell. The label and prompt are what the user sees in the Shape Data dialog, so be sure to include these. The Type cell specifies the data type of the shape data field. It is type string by default, but it can be a number, Boolean, fixed or variable list, date, duration, or currency. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 166 Note: If you double-click on the Type cell to enter text-edit mode, you will get a pull down list of the Type constant numbers and corresponding names. Having chosen a shape data field data type, you can then format the result of that data type. The Define Shape Data dialog provides some data type specific formatting lists to choose from, making it easier to format Shape Data values. Here are some examples: Data Type List Name ShapeSheet Format Number Whole number w/ units Currency $2.75 USD (0.00 UUU) “$4.89 USD” Date 10/03/93 (MM/dd/yy) “04/23/01” (0 u) Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals Result “3 in.” © 2010 Microsoft Corporation. All rights reserved. 167 Try it! Adding Shape Data fields 1. Open a new blank drawing and open <install folder>\Demos\Vol1\S7 Adding Data to Shapes\Adding Data Shapes.vss. 2. Instance into the drawing the shape Laptop computer. 3. Delete the local master from the document stencil. You can open the document stencil by selecting Shapes > More Shapes > Show Document Stencil when the drawing window is active. 4. Add the shape data fields “MFG”, “OWNER”, “DEPTCODE”, and “COST”. Right-click inside the ShapeSheet for the Laptop computer and select Insert Section …, after which you select Shape Data. 5. Add an Actions section (Insert Section …>Actions). Enter the formula “=DOCMD(1312)” into the Action cell, and “Edit Shape Data” into the Menu cell. This will allow the user to display the custom properties dialog via an RMA menu on the shape. 6. Set the following data for the custom properties. Name MFG OWNER DEPTCODE COST Type 4 0 1 7 Format “Dell;IBM;Micron” “Marketing;Development;Sales” 7. Set values for Label, Prompt, Sort Key, and Ask. 8. Drag the shape to the document stencil to create a new local master. Name the master. 9. Instance two or three times and fill in properties. Tip: Note: You can also access the Shape Data window from Data > Shape Data Window or right click the shape and choose Data > Shape Data. The DOCMD ShapeSheet function has not been documented since Visio 5.0. However, it is still used in many Visio shapes in conjunction with the supported “1312” constant, which loads the Shape Data dialog. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 168 Filling in Shape Data The Value cell is set using the Shape Data dialog. You cannot guard it, but you can enter an initial value that will be displayed in the Shape Data dialog dialog. The Ask cell controls whether the user is prompted for a value for the shape data field when the shape is first instanced or copied. If Ask=TRUE, Visio displays the Shape Data dialog on drop, duplicate, or paste. Note: Using the Ask cell to open the Shape Data dialog only shows the user the fields whose Ask cell has been set to true when a shape is first dropped. This is more selective. Using the DOCMD function in the RMA menu on the shape to open the Shape Data dialog will show all the properties to the user, as long as they are not invisible. The Invisible cell controls whether the property is displayed. If Invisible=TRUE, the property does not appear in the Shape Data dialog or reports. The Sort key is an ordinal number you enter. Properties are then listed in the Shape Data dialog in this order. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 169 Shape Data Sets Visio has tools for working with sets of shape data fields and copying these from one shape to other shapes. This feature provides a quick way to define and work with a collection of shape data fields and then apply them to one or many shapes or masters at once. To create shape data sets, define a name for the set and then add the shape data fields to be included. Then apply the set to selected shapes on the drawing page or to shapes on custom stencils. Accessing the Shape Data Sets window is done from the Shape Data window. 1. First, open the Shape Data window, Data > Shape Data Window. 2. Right mouse click in this window and choose Shape Data Sets. The Shape Data Sets window will be displayed. 3. From this window define a new set and its shape data fields. This window shows the current defined sets and gives you the ability to manage the existing sets or create a new one with the Add button. You can modify existing sets by clicking Define, Delete or Rename. You can use the Shape Data Set command to add sets of properties to the master shapes you select in an open custom stencil file. To add a shape data set to selected master shapes, follow these steps. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 170 1. 2. 3. 4. Open a custom stencil file. Open the Shape Data Sets window. In the Shape Data Set window, select the “Shapes selected in stencil” option Select the masters you wish to apply the property set to on the stencil and click Apply Try it! Create a new shape data set. 1. Open a document you wish to save the shape data set to. 2. Open the Shape Data Sets window 3. Create a new shape data set and define its properties. a. Click Add. In the Name box, type a name for the shape data set. Click OK. b. Click Define. The Define Shape Data dialog appears and lists Property 1 as the default. c. Define the new field by selecting the values you want for Label, Type, Format, Value and Prompt. 4. After you finish, click New to define another shape data field or OK to close the dialog. 5. A new shape data set has been created and stored with the document. 6. Select the shapes in the document you would like to apply the set to. 7. From the Shape Data Sets window select the name of the set to be applied. 8. Click OK to add the set of shape data fields to the selected shape. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 171 Using Shape Data in reports Since version 2002, Visio users have been able to use the data stored in shapes to create reports. This can be used to extract key data from a diagram, and allows the data to be leveraged in other applications, such as Excel and Access. Reports can also be used to create HTML documents for sharing on a company intranet, etc. Reports in Visio are created by extracting data from the Shape Data fields as well as some other shape information, such as the X, Y location on a page. In Visio 2007 the Reports tool has been moved from the Tools menu to the new Data menu. Visio has many reports pre-made for use. These reports are stored in Visio Definition Report (*.vrd) files in the installation directory, under the LCID folder for the installed language: for instance, C:\Program Files (x86)\Microsoft Office\Office14\1033 for English. Reports created in previous versions of Visio can be used in Visio 2010. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 172 Figure 1 - Filtered reports list You can generate a property report from the data entered into shape properties and custom properties. For example, you can generate an inventory report from the data stored with furniture and equipment shapes in an office layout. Or you can generate a list of the people represented in an organization chart, including their names and departments. You can generate reports in several of the most common formats. As a Web page (HTML file). A Microsoft Excel worksheet (.XLS). In structured XML format. You can also generate reports that are saved in a report shape that appears on your drawing: either a Visio table shape or an embedded Microsoft Excel object. Try it! Generate a property report 1. On the Review tab, click Shape Reports. 2. The Report dialog box displays as seen in image above. In the Report Definitions list, click the name of the report definition you want to use. 3. Click Run, and then in the Run Report dialog box, choose the report format you want. a. To save your report as a Web page, click HTML. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 173 b. To save your report as a Microsoft Excel spreadsheet, click Microsoft Excel (file). c. To save your report as a Microsoft Excel spreadsheet embedded in a shape in your drawing, click Microsoft Excel (shape). d. To save your report as a table that is placed on your drawing, click Visio Table Shape. e. To save your report as an XML file, click XML. 4. Do one of the following: a. If you are saving your report as a shape on the drawing, choose whether to save a copy of the report definition with the shape or link to a report definition. b. If you are saving your report as a file, type a name for the report definition. 5. To generate the report, click OK. To appear in the Report dialog box, report definitions should be stored your Drawings folder. The Visio drawing folder or folders is where drawings you create in Microsoft Visio are stored if you don't specify a different path. To find your drawing path, on the Tools menu, click Options, then Advanced. On the File Paths tab, the Drawings box shows the drawing folder location. You can add folders to this path. To modify a Property Report Definition You can modify an existing report using the Report Definition Wizard. 1. 2. 3. 4. On the Data menu, click Reports. Select a report definition, and then click Modify. Follow the Report Definition Wizard pages to modify the report definition. When you return to the Report dialog box, click OK to save your changes. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 174 Data1, Data2, Data3 Even very early versions of Visio supported the ability to add additional data to shapes. However, it was very limited, consisting of just 3 elements: Data1, Data2, and Data3. There were no Shape Data fields (a.k.a. Custom Properties) at the time so this was the only feature available to users for storing extra information in shapes. There is little or no need for this feature in current versions because both Shape Data and User-defined cells are much better tools for adding custom information to shapes. The feature is still there to support legacy applications. Access to the Data1, Data2, and Data3 storage areas is through the Shape Name dialog from the Developer tab. These elements do not show in the ShapeSheet, but they can be accessed through Visio’s automation model. Each of the three elements can contain up to 64KB of data Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 175 Figure 2 - Access to Data fields is through the Shape Name dialog Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 176 Scratch Section The Scratch work area has been in the product since the very early days. It is still a useful area for storing values or formulas, but it has been mostly superseded by User-defined cells because Userdefined cells can be named and Scratch cells cannot. This makes User-defined cells more programmer friendly. Each row has an X, Y, A, B, C, and D cells. More rows can be added as needed. X and Y are typed cells that default to drawing units, but they can take any length unit if the unit is specified. The A, B, C, and D cells are more general purpose. These cells can take numbers without units, number unit pairs, and formulas. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 177 Lab 1.7: Controlling a Shape using Shape Data Points to Consider Make a list of the shape data fields you will use, including their Labels, Prompts, Order in the Dialog, Default Values etc… The RGB function returns a value that represents an index of the document’s color palette. It specifies a color by its red, green and blue components, where each is a number in the range of 0 to 255. Here are some examples: Color Red Value Black 0 Green Value 0 Blue 0 0 255 Green 0 255 0 Cyan 0 255 255 Red 255 0 0 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals Blue Value 0 © 2010 Microsoft Corporation. All rights reserved. 178 Magenta 255 0 255 Yellow 255 255 0 White 255 255 255 The values for the RGB formula in the FillForegnd cell will come from values entered by the user into the Shape Data dialog. Therefore, the RGB formula will contain references to those shape data cells. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 179 Review: Adding Data to Shapes You have seen several tools that can be used to store additional data into Visio drawings. Here are some questions relating to what was covered in this section. Review Questions 1. What type of data can be stored in User-defined cells? 2. Describe a situation where it would be better to use Shape Data over User-defined cells. 3. How do you access Data 1, 2 & 3? Answers 1. Any type of data 2. Shape Data should be used when data is presented to and set by the user. User-defined cells are useful for storing programmatic data. 3. Developer > Shape Name dialog Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 180 Special types of 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. Containers Containers are new for Visio 2010 and provide a new way of collecting shapes together that is different from grouping. You can place other shapes into a container shape and they automatically become associated with the container. They move with the container. Containers are discussed in more detail below. Callouts Callouts are also new for Visio 2010. These aren’t the general callout shapes that have been used to annotate drawings with previous versions of Visio. These callouts have a special property that associates them to a shape they are connected to. However they aren’t glued in the normal sense. A shape can have many callouts. When a shape with callouts is moved, all of its callouts also move and maintain their original relative position. Callouts are discussed in more detail below. Legends Legend shapes are new for Visio 2010. Legend shapes can be added from the Data tab. Their purpose is to provide a legend for any Data Graphics used in the drawing. Legend shapes are implemented using the new Container shape. Once added, the legend can be modified by the user at any time. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 181 Backgrounds Background shapes are not new. What is new is that they have moved to the Design tab where they can be added from the ribbon rather than dragging and dropping from a stencil. Dropping a background shape onto a drawing page automatically creates a background page and associates that page with the drawing page. Try it! Working with Containers 1. 2. 3. 4. 5. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Container Samples.vsd Open the Demo page Choose Insert > Container and select a container from the gallery. With the new container selected hover over the gallery containers and note the live preview. Try to move the container by selecting in the filled area. The container is not selectable unless you pick on the header or on the bounder. This is controlled through the NoQuickDrag cell in the shape’s Geometry section. The NoQuickDrag cell determines whether a shape can be selected or dragged when the user clicks the filled area defined by the Geometry section. 6. Drop a shape into the container. Now drag the container. Note that the shape that was added to the container moves with the container. 7. Add another container and move it over an existing shape. Note the z-order. The new container shape appears behind even though it was the most recently added shape. There is a new feature for z-order banding that the shape developer can use to control multiple z-order bands. In previous versions of Visio there was no control of this feature. All shapes were assigned to the same band. Z-order banding is controlled by the Display Level cell in the Shape Layout section. By default, non container shapes have a zero value in this cell and container shapes delivered with Visio have a value of -25000 in this cell. As long as no other shapes are added to the drawing with a larger negative value in this cell, the container shapes will always appear behind. Structured Diagrams Collectively Containers, Lists and Callouts are referred to as Structured Diagram elements. They establish relationships with other shapes and those relationships define special behaviors. For example, shapes placed into a list are automatically arranged adjacent to one another; a callout shape moves whenever its target shape is moved. Structured Diagram elements are shapes themselves, and thus the special behaviors are defined through their ShapeSheet cells and values. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 182 To designate any shape as a Container, List or Callout you only need to add one User-defined cell called User.msvStructureType. For the value enter “Container”, “List” or “Callout” as desired. This setting tells Visio that the shape is a Structured Diagram element and adds many of the Structured Diagrams behaviors to the shape. In the image below, a rectangle shape is transformed into a container shape by adding the User.msvStructureType cell and setting it to “Container”. However, there are additional settings available to customize the appearance and behavior of your shape. These are described below. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 183 Containers Container shapes are designed to automatically sit behind other shapes on the page and keep track of any shapes that are associated or “contained” within them. This is a new and distinct feature from groups. The contained shape can always be selected and manipulated independently of the container. By contrast, if a shape is in a group the user must first select the group and then subselect the shape in order to do something with it. The cross functional flowchart solution in Visio has been revamped for Visio 2010 to implement each of the individual Swimlanes and each of the Phase shapes as containers. Now when you add shapes to a cross functional flowchart, you are adding these shapes to Swimlane containers and to Phase containers. Each Swimlane and Phase shape is a special type of container that is automatically placed next to a shape of the same type. To keep track of all of the Swimlane shapes there is a special type of container which is of type List. There is a Swimlane List shape whose purpose is to hold all of the individual Swimlanes. There is also a Phase List shape that holds all of the Phase container shapes. Container Shape Details Any shape with User.msvStructureType = “Container” is treated by Visio as a Container. The following ShapeSheet cells define additional container properties, several of which can be configured in the Container Tools contextual tab in the Ribbon. Cell Name Description User.msvSDContainerMargin Distance between container boundary and member shapes User.msvSDContainerResize Automatic resize behavior for shape (0 = No automatic resize; 1 = Expand as needed; 2 = Always fit to contents) User.msvSDContainerStyle 1-based index value for the current visual style of the container User.msvSDContainerStyleCount Total number of visual styles supported by the container Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 184 User.msvSDHeadingStyle 1-based index value for the current visual style of the container heading User.msvSDHeadingStyleCount Total number of visual styles supported by the container heading User.msvSDContainerLocked Boolean value that prevents membership changes in the container User.msvSDContainerRequiredCategories Semi-colon delimited list of category names. Other shapes must have at least one matching name to be allowed as container members. User.msvSDContainerExcludedCategories Semi-colon delimited list of category names. Other shapes with at least one matching name are disallowed as container members. User.msvSDContainerNoHighlight Boolean value that suppresses the container highlighting when member shapes are selected or added to container User.msvSDContainerNoRibbon Boolean value that hides the Container Tools contextual tab in the Ribbon for this container User.msvSDContainerHeadingEdge String designating where the interior of the container is from the perspective of the container heading. Must be either “Left”, “Right”, “Top” or “Bottom”. User.msvSDMembersOnHiddenLayer Boolean value that determines whether Visio severs container relationships when the container or member is placed on a hidden layer. If True, Visio allows relationships to exist on the hidden layer. If False, Visio severs the relationships. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 185 Try it! Create a basic container 1. 2. 3. 4. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Container Samples.vsd Open the Basic page Draw a rectangle Open the rectangle’s ShapeSheet and add the cell User.msvStructureType=”Container”. This will cause Visio to treat the shape as a container. Drop another shape into the rectangle and note that it is captured by the rectangle container shape. 5. Look at the ShapeSheet for the Simple Heading shape. It has some additional User cells to override some default container behaviors. It also has a value of -25000 in the Display Level cell in the Shape Layout section. 6. There are two container shapes on the page that display a count for Members and Parents. Add shapes to these containers and note the change in Member count. Add one container to the other and note that the Parent count is incremented. 7. Open the ShapeSheet for one of these containers and look at the User section there are two cells User.MemberCount and User.ParentCount with references to ShapeSheet functions CONTAINERMEMBERCOUNT() and MEMBERCOUNT(). Creating a visual style If you are creating a container shape from scratch, you will notice that by default the container does not have any Container Style or Heading Style available in the Container Tools tab. Styles are a way to offer different looks for your container through some combination of geometry and formatting changes. The container shape can define multiple visual styles using the User.msvSDContainerStyle, User.msvSDContainerStyleCount, User.msvSDHeadingStyle and User.msvSDHeadingStyleCount cells (in short, the “Style” cells and the “Count” cells). Use the Count cells to tell Visio how many styles your shape supports for the overall container or for the heading. Then determine what ShapeSheet cells should be set for each style. Put formulas in each of these cells that depend on the value of the Style cells. Visio will check the style count and populate the ribbon galleries with each style defined by the container shape. When the user chooses a new style from the gallery, Visio puts that style index back into the Style cells to update the look of the container. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 186 The container shapes in Visio 2010 vary in complexity. The containers in the Insert Container gallery have many visual styles and lots of formulas to change the appearance of the shapes. There are some simpler examples in the Wireframe shapes, which define just a few styles each. Note: The use of the term style in this context is completely independent of the Style feature used in Visio before Themes were introduced to the product. Try it! Creating container shapes will multiple styles 1. 2. 3. 4. 5. 6. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Container Samples.vsd Open the Styles page Select the container shape. On the ribbon select the Container Tools tab. Note that the Container Styles gallery has two styles defined for this container. Select the styles and note the change in the shape. Note that the portion of the shape labeled Header turns on and off with the selections. 7. Use the Drawing Explorer to see the structure of the container. It is a group shape with two child shapes: one for the header section and one for the body section. 8. Open the ShapeSheet for the container. It has cells User.msvSDContainerStyle, User.msvSDContainerStyleCount, User.msvSDHeadingStyle and User.msvSDHeadingStyleCount. 9. View the ShapeSheet of the Header portion of the container. Note the formula in Geometry1.NoShow=IF(Sheet.1!User.msvSDContainerStyle=1,FALSE,TRUE). Amd HideText=IF(Sheet.1!User.msvSDContainerStyle=1,FALSE,TRUE) . When a style is chosen, the Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 187 index of the style in the list is stored in the User.msvSDContainerStyle cell. The formulas control whether the geometry and the shape text are displayed. Tip: Build your containers as multi-shapes when you want to apply multiple styles. As a shape developer you need to define each style within your container shape. You do this by using existing shape development skills, building geometry that shows and hides based on ShapeSheet formulas just as if you were building a multi-shape that morphs based on the selection of a smart tag or the setting of a Shape Data value. Creating a heading sub-shape The heading of a container is simply the container shape’s text for basic containers. However, it is possible to achieve more sophisticated visual styles if the heading becomes its own shape. For this construction the container becomes a group and the heading is added as a sub-shape of the group. The primary benefit is that Visio can account for the heading sub-shape in sizing and layout operations to avoid putting member shapes on top of the heading. To designate a sub-shape as a heading for the container, add the cell User.msvStructureType to the sub-shape and give it the value “Heading”. Also you should properly set the User.msvSDContainerHeadingEdge cell in the sub-shape. These cells helps Visio understand how the heading is positioned relative to the interior of the container. For example, if the heading is near the left edge of the container then the correct value for the cell is “Right” (regardless of the heading’s angle). The interior of the container is on the right side of the heading. Try it! Creating container shapes will multiple styles 1. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Container Samples.vsd 2. Open the Styles page 3. Look at the ShapeSheet for the Header portion of the shape labeled Syle. It has a cell User.msvStructureType = “Heading” Controlling container membership Visio 2010 introduces the concept of Shape Categories to refine the membership behaviors of containers. This is the mechanism used by features such as Cross-functional Flowchart and Data Graphic Legends to ensure that only the right kinds of shapes participate in the list and container behaviors. A container shape can restrict membership by defining a required or excluded shape category. For this to work, a prospective member shape must have a User-defined cell User.msvShapeCategories in its ShapeSheet. The prospective shape lists one or more category names in a semi-colon delimited string. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 188 To only allow a specific category of member shape, a container can set that name in its User.msvSDContainerRequiredCategories cell. To allow most shapes as members but specifically exclude a category, a container can set that name in its User.msvSDContainerExcludedCategories cell. (Prospective shapes with no categories defined will not be allowed in a container with required categories, and they will always be allowed in a container with excluded categories.) Try it! Controlling container membership 1. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Container Samples.vsd 2. Open the Categories page 3. Look at the ShapeSheets for the container shapes. Note they have cells User.msvSDContainerRequiredCategories and User.msvSDContainerExcludedCategories. 4. Look at the ShapeSheets for the square shapes. Note that the colored shapes have the cell User.msvShapeCategories which defines the categories each shape belongs too. The white square has no categories defined. 5. Add the squares to the containers and note which ones are accepted by the container and which are not. Showing custom shapes in the Insert Container gallery Visio provides several built-in container shapes in the Insert Container gallery located on the Insert tab of the ribbon. It is possible to override this set of shapes by creating a specially named stencil with other container shapes. Create a stencil named _CONTAIN.vss and place it in the user’s My Shapes folder. Using automation to get information about containers Most of the functionality of working with containers is held in the new object ContainerProperties. Since a container is a Visio shape you work with it in the same way you would any other shape. To resize a container to fit its contents use the FitToContents method of the ContainerProperties object. To lock a container so that shapes cannot be added or taken away, use the LockMembership property of the ContainerProperties object. Adding shapes to containers can be done from either the Shape or Selection objects or from the ContainerProperties object. o Using AddToContainers from the Shape or Selection object is equivalent to Add to Underlying Container from the user interface. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 189 o To add a shape to a specific container, use the AddMember method of the ContainerProperties object. To get a list of all containers on the page use the GetContainers method of the Page object. Deleting a container using the normal shape delete will also delete all of the shapes within it. To delete a container, but retain the shapes use the Disband method of the ContainerProperties object. To get a list of all shapes within a container use the GetMemberShapes method of the ContainerProperties object. This returns an array of shape IDs. Try it! Accessing container information 1. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Container Samples.vsd 2. Open the Basic page 3. Run the macro Macros.GetContainers. Open the Visual Basic window (Alt-F11 or Developer > Visual Basic). The results of the macro are displayed in the Immediate window. Public Sub GetContainers() 'use GetContainers method to get the containers on the page Dim i As Integer Dim containers() As Long containers = ActivePage.GetContainers(visContainerExcludeNested) Debug.Print "all page level containers" For i = 0 To UBound(containers) Debug.Print ActivePage.Shapes.ItemFromID(containers(i)).Name Next containers = ActivePage.GetContainers(visContainerIncludeNested) Debug.Print "all containers on the page" For i = 0 To UBound(containers) Debug.Print ActivePage.Shapes.ItemFromID(containers(i)).Name Next End Sub 4. Note that the GetContainers method takes a flag values visContainerExcludeNested or visContainerIncludeNested. If visContainerExcludeNested is specified, any nested containers Microsoft Visio 2010 Developer Training © 2010 Microsoft Corporation. All rights reserved. Volume 1: Shapes and ShapeSheet Fundamentals 190 will not be included in the results. The GetContainers method returns an array of shape IDs. The ItemFromID method is then used to retrieve a reference to the shape. 5. On the page put some containers within other containers and run the macro Macros.GetContainers again. Note which containers are listed at the page level. 6. Place some shapes within a container. Select the container and run the macro Macros.GetMemberShapes. The results are displayed in the Immediate Window. Public Sub GetMemberShapes() 'use ContainerProps.GetMemberShapes to get the member shapes of a container Dim shp As Visio.Shape Dim members() As Long Dim i As Integer If ActiveWindow.Selection.Count = 0 Then MsgBox "select a container shape" Exit Sub Else Set shp = ActiveWindow.Selection(1) End If If shp.ContainerProperties Is Nothing Then MsgBox "select a container shape" Else members = shp.ContainerProperties.GetMemberShapes(visContainerFlagsExcludeContainers) Debug.Print "members of the container" For i = 0 To UBound(members) Debug.Print ActivePage.Shapes.ItemFromID(members(i)).Name Next End If End Sub Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 191 7. The macro uses ContainerProperties.GetMemberShapes(visContainerFlagsExcludeContainers). This causes the method to return only member shapes which are not themselves containers. Other flags are available including: a. visContainerFlagsDefault = 0. Returns all shape types and includes items in nested containers. b. visContainerFlagsExcludeContainers = 1. Excludes member shapes that are containers. c. visContainerFlagsExcludeConnectors = 2. Excludes member shapes that are connectors. d. visContainerFlagsExcludeCallouts = 4. Excludes member shapes that are callouts. e. visContainerFlagsExcludeElements = 8. Excludes member shapes that are not containers, lists, connectors, or callouts. f. visContainerFlagsExcludeNested = 16. Excludes any member shapes that are members of containers or lists nested within the container. g. visContainerFlagsExcludeListMembers = 32. Excludes members of a list container that are explicitly members of any list. Does not exclude other shapes in the list container. 8. Note the If test to determine that a proper container has been selected. A shape that is not a container does not have a valid ContainerProperties object. Dropping containers with automation If you create a new flowchart from a template and then check the open documents you will see only the document for your drawing and the stencil BASFLO_U.VSS. To add Containers go to the Insert tab and select the Container to add. The Containers are shapes, but the Container masters are not shown in the Shapes window. They are shown as part of ribbon interface. So how do we get to these containers programmatically? As it turns out, there are stencils holding the Containers, Callouts, and Legends for Visio 2010. Luckily, these can be accessed like any other stencil. The first step is to find the path to these stencils. Then you can open them programmatically and work with them as you normally would. The path can be gotten from the GetBuiltInStencilFile method of the Application object . Ask for the type of file (container, callout, etc.) and the measurement units (Metric or US). The method will return a string containing the path to the stencil. Once you have the path you can open the stencil. Public Sub OpenContainerStencil() 'Open the stencil holding the Container objects and print the ‘names of the masters Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 192 Dim strContainers As String strContainers = Application.GetBuiltInStencilFile(visBuiltInStencilContainers, visMSDefault) Debug.Print strContainers Dim stencil As Visio.Document Dim master As Visio.master Dim shape As Visio.shape Dim container As Visio.shape 'open the stencil 'Set stencil = Application.Documents.Open(strContainers) 'open the stencil hidden 'Set stencil = Application.Documents.OpenEx(strContainers, Visio.visOpenHidden) 'open the stencil docked in the shapes window 'Set stencil = Application.Documents.OpenEx(strContainers, Visio.visOpenDocked) 'print the names of the masters in the Immediate window For Each master In stencil.Masters Debug.Print master.Name Next 'stencil.Close End Sub The method GetBuiltInStencilFile can be used to get the path for containers, callouts, borders, legends, and backgrounds. The sample code includes a couple of options to open the stencil as docked or as hidden. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 193 You may not want to just drop containers on the page using the Page.Drop method because a Container shape has a special ability to capture any selected shapes when it is dropped. When adding containers through the user interface you have the following options: Insert Container with shapes selected. The container is dropped, sized and positioned so that it captures all of the selected shapes. Insert Container with no shapes selected. The container is dropped in the center of the viewing area at its default size. If there are shapes in this area, the container will NOT capture them. The code sample below shows how to drop a container with either the Page.Drop method or the Page.DropContainer method. Sub TestPageDropContainer() Dim strContainers As String Dim stencil As Document Dim master As Visio.master Dim container As Visio.shape Dim selection As Visio.selection 'Get the path to the Container stencil and open it strContainers = Application.GetBuiltInStencilFile(visBuiltInStencilContainers, visMSDefault) Set stencil = Application.Documents.OpenEx(strContainers, Visio.visOpenHidden) 'Get a reference to the first container master Set master = stencil.Masters.Item(1) Debug.Print master.Name 'Drop the container using Page.Drop. This method will not capture a shape. Set container = ThisDocument.Pages(1).Drop(master, 5, 5) 'Drop the container and specify a shape or selection to capture Set container = ThisDocument.Pages(1).DropContainer(master, ThisDocument.Pages(1).Shapes(1)) Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 194 'You can also pass an empty selection to the DropContainer method Set selection = Nothing Set container = ThisDocument.Pages(1).DropContainer(master, selection) End Sub The last line of code creates a container using DropContainer, but is given an empty selection. When tested with the Techincal Preview version of Visio this method drops the Container onto the center of the page even if the center of the page is not within my viewing area. Working from the UI the container would be placed in the center of the viewing window. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 195 List Shape Details Any shape with User.msvStructureType = “List” is treated by Visio as a List. Note that Lists are also considered to be Containers. They simply have the additional capability of ordering and arranging their member shapes. All of the previously mentioned Container cells apply to list shapes. The following ShapeSheet cells define additional list properties. Cell Name Description User.msvSDListAlignment Determines how member shapes are aligned in list (0 = Left; 1 = Center; 2 = Right for vertical lists. 0 = Top; 1 = Middle; 2 = Bottom for horizontal lists.) User.msvSDListDirection Direction that list arranges member shapes (0 = Left to Right; 1 = Right to Left; 2 = Top to Bottom; 3 = Bottom to Top) User.msvSDListSpacing Distance between list members User.msvSDListItemMaster Name or UniqueID of master shape to instance on Insert commands. Value must be placed inside a USE() function. User.msvSDListNoReorder Boolean value that prevents reordering of members. The list must also be locked via User.msvSDContainerLocked = True for setting to have any effect. User.msvSDListRequiredCategories Semi-colon delimited list of category names. Other shapes must have at least one matching name to be allowed as list members. User.msvSDListExcludedCategories Semi-colon delimited list of category names. Other shapes with at least one matching name are disallowed as list members. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 196 Specifying a shape to insert into lists There are several ways to add a shape to a list: dragging and dropping the shape, clicking the blue insertion arrow that appears near the list edge or right-clicking an existing member and inserting a shape. Clicking the insertion arrow and right-clicking to insert both use the User.msvSDListItemMaster cell to determine what shape to add to the list. The name of the shape is placed in quotes inside a USE() function, such as USE(“Member shape”). It is also possible to automatically populate the list with some member shapes when the list is first dropped on the page. To do this put the following formula in the EventDrop cell of the list, repeating the DOCMD(2270) once for each member to be added: IF(LISTMEMBERCOUNT()=0,DOCMD(2270)+DOCMD(2270)+DOCMD(2270),0) Controlling list membership Lists have their own cells to govern list membership. Use the User.msvSDListRequiredCategories and User.msvSDListExcludedCategories cells to restrict what shapes can become list members. Because lists are also containers, it is possible for shapes to become container members of the list. The standard User.msvSDContainerRequiredCategories and User.msvSDContainerExcludedCategories cells determine this behavior. By default Visio will attempt to add a shape to a list as a list member, but if that fails it may try to add it as a container member. You should manage both sets of cells to ensure the right results. Try it! Working with List shapes 1. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Container Samples.vsd 2. Open the Lists page 3. Open the ShapeSheet for the Shapes list. It has User.msvStructureType=”List” User.msvContainerMargin=0.125 The msvContainerMargin cell sets the margin between the contained shapes and the container border. 4. Open the ShapeSheet for the Vert list. There is no User.msdListSpacing specified so it defaults to zero. 5. Open the ShapeSheet for Horz list. User.msvListSpacing=0.25 in Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 197 This provides quarter inch spacing between shapes added to the List. 6. Open the ShapeSheet for the List displaying the Item Count. Note the User.ListItems cell uses LISTMEMBERCOUNT() to get the count of the number of members in the list. 7. Open the ShapeSheet for one of the members in this container. Note the User.IndexInList cell uses LISTORDER() to get the index of the member within the list. Try it! Working with Containers and Lists using automation This file contains custom Container and List shapes and has linked data. The automation code reads the data records and adds one container and server for each record in the Machines datarecordset. It then adds the Disk List container for each server and populates the container with a Hard Drive shape for each record in the Drives datarecordset. 1. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Container and List Samples - VBA.vsd 2. Run the macro BuildFromDataSets. The resulting drawing should look like the following image. 3. View the VBA code. About 25 lines in is the following code. ' turn on diagram services Dim diagramServices As Visio.VisDiagramServices diagramServices = ActiveDocument.DiagramServicesEnabled ActiveDocument.DiagramServicesEnabled = _ Visio.VisDiagramServices.visServiceAll At the end of the macro is the following code. ' reset diagram services now that we are done Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 198 ActiveDocument.DiagramServicesEnabled = diagramServices Diagram services is a new feature that allows the solution developer to enable and disable specific behaviors for some of the new features in Visio 2010. Because the Visio engine recognizes containers it is able to maintain the relationships with the member shapes. As the user moves a container the engine provides the service for moving the member shapes relative to their container. This behavior in automated solutions is turned off by default. It is important to understand that this setting does not affect the UI. All these behaviors are turned off by default but this only affects automation. If you move a container shape by setting the container’s PinX and PinY cells using automation and you do not turn on the Container behaviors prior to setting these cells, the container will move but the member shapes will not. As you use this setting it is best to follow the same best practices that you use when changing other settings, such as with EventsEnabled. Keep track of the current value and set it back when you are done with your modification. To drop a Server shape, link it to its data row, and apply a data graphic to it. ' add the machine Dim machine As Visio.Shape Set machine = ActivePage.DropLinked(masterMachine, 0, 5, _ machinesDataset.ID, nextRowId, False) ' apply a data graphic to this shape machine.DataGraphic = datagraphicMachine The following is the code to add the disk list shape. ' add the disk list Dim disks As Visio.Shape Set disks = ActivePage.Drop(masterDiskList, 1, 5) The following drops the machine container and captures the Server shape and the Disk List shape at the time it is dropped. The second parameter of the DropContainer method is a Visio selection of what is be captured by the container. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 199 ' drop the machine container and tell it to contain the machine and the disk list Dim machineContainer As Visio.Shape Set machineContainer = _ ActivePage.DropContainer(masterMachineContainer, continees) machineContainer.Text = machineName The DropLinked method is also used to drop the Hard Drive shape. A data graphic is applied and then the Hard Drive is added to the List using ContainerProperties.InsertListMember method. Dim nextDisk As Visio.Shape Set nextDisk = ActivePage.DropLinked(masterDisk, 0, 0, diskDataset.ID, nextDiskRowId, False) ' apply our data graphic to each disk nextDisk.DataGraphic = datagraphicDisk ' add to the list container disks.ContainerProperties.InsertListMember nextDisk, 1 Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 200 Callout Shapes There is a new type of shape in Visio 2010 called a Callout. There have been callout shapes in Visio stencils in previous versions of the product, but this new callout shape is different. The new Visio 2010 Callout: Can be associated with another shape (a “target” shape) without gluing Will maintain the same relative position to the target shape whenever the target shape is moved Will always be shown on top of the target shape To add a callout to the drawing go to the Insert tab and choose Callout. A list of callouts is presented from which to choose. Select the desired callout style and it is added to the page. If no shape is selected when the callout is added, the callout will be added at the center of the viewing window and will not be associated with any shape If one or more shapes is selected a callout of the chosen type will be added to each selected shape. To associate a callout with a shape, drag the callout’s control handle over another shape. If the callout can be associated with the shape a yellowish/orange rectangle is displayed around the target shape. Releasing the control associates the callout and the shape. Once associated, the target shape can be moved and the callout will move along with it and will always maintain the same relative position to the target shape. Any shape with User.msvStructureType = “Callout” is treated by Visio as a Callout. Callout shapes must also have a control handle with the Controls row named Controls.Association. Visio manages the relationship with the callout’s target shape through this row in the ShapeSheet. The following ShapeSheet cells define additional callout properties. Cell Name Description User.msvSDCalloutNoHighlight Boolean value that suppresses the highlighting on the callout target shape User.msvSDTargetIntersection Location in page coordinates of the intersection between the geometric boundary of the target shape Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 201 and a virtual line drawn from the center of the callout to the center of the target shape. This is a read-only cell set by Visio. Showing custom callout shapes in the Insert Callout gallery Visio provides several built-in callout shapes in the Insert Callout gallery located on the Insert tab of the ribbon. It is possible to override this set of shapes by creating a specially named stencil with other callout shapes. Create a stencil named _CALLOUT.vss and place it in the user’s My Shapes folder. Dissecting the Callout shape This behavior of the Callout shape is not created just with ShapeSheet formulas. Visio manages this behavior based on some special cells created in the ShapeSheet that identify the shape as a Callout. If we view the ShapeSheet it does look rather complex, but a lot of this complexity has to do with the display of the callout shape. Let’s break it down. If we eliminate those parts used for display, what is left will be the essential cells required to define a shape as a callout. The Callouts chosen from the ribbon are all multi-shapes. In fact, they are each the same. Any individual callout added to the drawing can be modified into one of the 20 other callout types simply with a right mouse menu selection. Thus there are twenty geometry sections and twenty menu items just to change the callout type. The following User cells are used to control the type of callout: o User.msvSDCalloutStyle o User.msvSDCalloutStyleCount The Leader line can be oriented so that it originates from the Top, Bottom, Left, or Right of the callout shape. It can also be hidden. The following Action section rows are used to set options on the leader line: o Actions.OrientTop o Actions.OrientBottom o Actions.OrientLeft o Actions.OrientRight o Actions.OrientAuto o Actions.LeaderHidden o Actions.LeaderCenter o Actions.LeaderMidpoints There is also one Action cell that controls how the shape resizes with text. Cells to support this action are: Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 202 o Actions.ResizeWithText o User.ResizeWithText Most of the User section is there to control the start and end positions of the leader line and the leader line’s visibility. Because the callout is always on top of the shape it is associated with, the leader line must be trimmed precisely to the edge of the shape. Most of the cells in the User section are used to calculate the proper trim points. Cells related to managing the leader line include: o User.Orientation o User.HideLeader o User.AttachToSide o User.Side o User.LeaderBegin o User.LeaderEnd o User.WHBoxIntersection o User.IsEndInterior o User.Extension o User.Inset o User.SideMidPoint o User.fnMidpointOffset This leaves the following cells that are the only ones required to define a shape as a Callout shape User.msvStructureType=”Callout” – defines the shape as a Callout shape User.msvSDTargetIntersection – stores the offset between the Callout and the target shape Controls.Association – a control with this name is required for a Callout shape Creating Custom Callout shapes The Callout shape has some interesting properties that would be really useful if they could be adapted into new shapes. For example, a callout shape when associated with a target shape will move along with the target shape without having to group or glue the shapes together. Thus a custom callout could serve as an alternative to 2D glue or to shape solutions that use SETATREF to associate shapes. We have just determined that the essential cells needed to define a shape as a Callout shape are User.msvStructureType=”Callout”, User.msvSDTargetIntersection , and Controls.Association. Any shape can be turned into a Callout shape by adding these two User cells and the Control. In the example below each square of the game board has been created as a Callout and associated with the Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 203 yellow border. When the board is moved, each red and black square moves with it because of the association. Try it! Open the sample file with the above example 1. 2. 3. 4. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\Custom Callout.vss. Read the information in the file. Unlock the layer and open the ShapeSheet for one of the custom callouts. Check the User Section and the Controls section for the cells required for a shape to be a callout. Using automation with Callouts There are also a few important methods and properties for the automation programmer. To add a new callout to the page use Page.DropCallout. This drops the callout and associates it with a target shape and positions it near the target shape. To get a list of all callouts on a page use the GetCallouts method of the page. This returns a list of shape IDs. Callouts that are nested within containers can optionally be included or excluded from the list. To find the callouts associated with a shape use the shape objects CalloutsAssocciated property. To get the target shape of a callout shape use callout shape’s CalloutTarget property. Test whether a shape is a callout with the shape’s IsCallout method. Try it! Open the sample file with the above example 1. Open the file <install folder >\Demos\Vol1\S8 Special Types of Shapes\ DropCallouts.vss. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 204 2. Select the Treasurer shape and run the macro AddCalloutToShape. The code is shown below. Public Sub AddCalloutToShape() 'add a callout to the selected shape Dim shp As Visio.Shape Dim calloutMaster As Visio.master Dim strCallouts As String Dim stencil As Visio.Document Dim calloutShape As Visio.Shape Dim master As Visio.master Dim calloutIDs() As Long Dim i As Integer If ActiveWindow.selection.Count = 0 Then MsgBox "select a shape" Exit Sub Else Set shp = ActiveWindow.selection(1) End If 'Get the path to the Callout stencil and open it strCallouts = Application.GetBuiltInStencilFile(visBuiltInStencilCallouts, visMSDefault) Set stencil = Application.Documents.OpenEx(strCallouts, Visio.visOpenHidden) 'Get a reference to the first container master Set master = stencil.Masters.Item("Bracket") 'Drop the callout Set calloutShape = ActivePage.DropCallout(master, shp) calloutShape.Text = "Reward employee if idea is implemented" 'you can get the target shape from the callout Debug.Print calloutShape.CalloutTarget.Name Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 205 'find the callouts associated with the shape calloutIDs = shp.CalloutsAssociated 'alternatively, find all callouts on the page 'calloutIDs = ActivePage.GetCallouts(visContainerExcludeNested) 'print the callout shape names For i = 0 To UBound(calloutIDs) Debug.Print ActivePage.Shapes.ItemFromID(calloutIDs(i)).Name Next End Sub Getting a callout master is the same as getting a container master. Start by using GetBuiltinStencil to get the path to the stencil file. Then open the stencil as hidden. Now you have a document reference and get the reference to the desired master. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 206 Summary for Special types of shapes The new shapes for Visio 2010, Containers, Lists, and Callouts all require the User.msvStructureType cell to tell Visio what type of shape behavior they require. There is a rich set of User cells that can be used to refine the look and feel of the shapes and the automation model fully represents all of the features so that a complete automation solution can be established. Microsoft Visio 2010 Developer Training Volume 1: Shapes and ShapeSheet Fundamentals © 2010 Microsoft Corporation. All rights reserved. 207