3 4
The appearance of a shape in a drawing, however sophisticated, is rarely the whole story. The real-world object that a shape represents often has important data associated with it—part numbers, prices, quantities ordered or in the warehouse; names, dates, addresses, telephone numbers; manufacturers, suppliers, customers; dimensions, materials, tensile strength. Having this kind of data in a drawing makes it a powerful tool for analysis and communication.
You can associate data with a Microsoft Visio shape by defining custom properties in its ShapeSheet spreadsheet, or by working in the Custom Properties window or dialog box or in the Define Custom Properties dialog box. You give each custom property a unique name and optionally define other characteristics, such as data type, format, and default value.
This section introduces using ShapeSheet formulas to define and edit custom properties. You can also use Automation to integrate information from other sources into your Visio drawings. For details, see Chapter 20, Integrating Data with a Visio Solution.
Custom properties open a world of possibilities for making your solutions richer and more reflective of the real-world systems they describe. Some of the things that you can do with data that is associated with your shape include the following:
Sometimes data stays behind the scenes, but often you'll want to display data in a drawing or change the drawing as the data changes. You can use a shape's custom properties to do the following:
Custom properties can serve as containers for data from an external source, or they can provide a data-entry interface for shapes in a drawing. Whether custom property data resides in only the shape or interacts with an external source is up to you.
For example, you can use custom properties to update an inventory control list. You can create a stencil containing masters that represent the parts in inventory. For each master, you might define the custom properties Name, Price, and Quantity. You can set the value of these properties when you create the shapes, or you can allow the shapes' users to enter the name, price, and quantity for a given part, even prompting users to do so.
Figure 7-8 Custom properties for an inventory control list (A) Shape with custom properties. (B) The value typed here is the value of the Prop.Cost cell.
You can define a custom property to store string, numeric, Boolean, date or time, duration, currency, fixed list, or variable list data with any object represented by a sheet, such as a shape, group, master, guide, page, or document. A custom property is stored as a ShapeSheet row whose name and cells you define. You can view and modify custom properties through the Visio menu commands, as well as create reports from the information or refer to the values in other ShapeSheet cells. Custom properties are a way to associate database-like fields with a shape or a page.
If you want to create a custom property to hold data, but you do not want that data to be visible in the Custom Properties window or dialog box, you can set a shape's Invisible cell (Custom Properties section) to TRUE. The GUARD function cannot protect the data in the Value cell of a Custom Property row.
You can define custom properties for a single shape or a page by adding a Custom Properties section to its sheet or by working in the Custom Properties window or dialog box. If you're editing a stencil, a more efficient method is to define custom properties for the stencil's masters so that their instances also contain the properties.
The Custom Properties window provides a convenient at-a-glance view of the custom properties associated with a page or a selected shape, as well as an interface for entering new values for those properties.
Figure 7-9 You can enter new values for custom properties in the Custom Properties window.
Note
Note
For example, type Unit_Cost and press ENTER to create the custom property Prop.Unit_Cost. The name that appears in the Row label is the cell name for the Value cell in that row. Use this name (for example, Prop.Unit_Cost) in cell references.
For example, type Cost Per Unit. Visio automatically encloses the string in quotation marks.
For example, type Enter the cost per unit for the part. Visio automatically encloses the string in quotation marks.
For details, see the following table.
To see the custom property you have defined, select the shape on the drawing page or cancel all selections if you want to view the page's custom properties. Then click Custom Properties on the Shape menu.
Custom property types and format
Type | ShapeSheet cell formula | Description |
String | Type = 0 Format = "<picture>" | This is the default. Use a valid format picture* in the Format cell to format strings as number-unit pairs, dates, times, and so on. |
Fixed list | Type = 1 Format = "Item 1;Item 2" | Displays the list items alphabetically in a drop-down list box in the Custom Properties dialog box. Specify the list items in the Format cell. Users can select only one item from the list. |
Number | Type = 2 Format = "<picture>"` | Use a format picture* in the Format cell to specify units of measure and other number formats. |
Boolean | Type = 3 | Displays FALSE and TRUE as items users can select from a drop-down combo box in the Custom Properties dialog box. |
Variable list | Type = 4 Format = "Item 1;Item 2" | Displays the list items in a drop-down combo box in the Custom Properties dialog box. Specify the list items in the Format cell. Users can select a list item or enter a new item; new items are added to the list. |
Date or time | Type = 5 Format = "<picture>" | Use a format picture* in the Format cell to specify days, months, years, hours, minutes, seconds, or other date formats; time formats; or combination of date and time formats. |
Duration | Type = 6 Format = "<picture>" | Use a format picture* in the Format cell to specify elapsed time in hours, days, weeks, months, or other duration formats. |
Currency | Type = 7 Format = "<picture>" | Use a format picture* in the Format cell to specify currency formats. |
* For example, [Format = "# #/10 UU"] formats the number 10.92 cm as "10 9/10 CENTIMETERS" (specifying the use of "10" in the denominator and the uppercase, long form of the units). For details about valid format pictures, see Formatting Strings and Text Output in Chapter 9, Designing Text Behavior. Or search for "format function" in the Microsoft Visio Developer Reference (on the Help menu, click Developer Reference).
After you have defined custom properties for a shape, you can link the data to a database. By establishing connections between shapes and database records, you can create Visio drawings that function as visual representations of data. For example:
The Database Wizard can automate this process for you. It links the values of ShapeSheet cells in the Custom Properties section to a database created in an application compliant with the Open Database Connectivity (ODBC) standard, such as Microsoft Access 7.0 or later, or Microsoft SQL Server. If you revise the database, you can refresh the values in the ShapeSheet cells to reflect the revisions. Once you've established a shape-record connection, you can pass information back and forth between your Visio drawing and the database and keep the two versions of the data synchronized.
When it links a shape to a database, the Database Wizard adds the Custom Properties and User-Defined Cells sections to the shape's sheet. The wizard stores information about the primary key for the database, the database fields that are linked to ShapeSheet cells, and the last valid data retrieved from the database in user-defined cells.
To run this wizard, on the Tools menu, point to Add-Ons (or point to Macros if you're not running in developer mode), point to Visio Extras, and then click Database Wizard. For details about options, click Help in the wizard.