Custom Properties

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.

Using Custom Properties

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:

  • Add data when you create a shape For example, you might define custom properties for resistance, voltage, and amperage and enter data for them in masters that represent electronic components. When the user drops one of the shapes in a drawing, the data accompanies the shape.
  • Collect data from a user Microsoft Visio can prompt the user to fill in custom properties of a master each time it is dropped in a drawing, encouraging the user to enter the data that your solution needs. The user can also display and edit a shape's custom properties from its shortcut menu.
  • Display data in a shape's text You can insert a text field in the shape's text to display the result of a custom property's formula. A text field can display a value, the result of a formula, or any global value that the Visio engine provides, such as file summary information or the current date and time.

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:

  • Control a shape's behavior Because custom properties are stored in ShapeSheet cells, they can play a role in other formulas—for example, a shape's geometry can be linked to its custom properties, allowing the shape to respond to user input.
  • Extract data from a drawing You can obtain data from a shape's custom properties and write it to an external destination such as a spreadsheet or database. For details, see Chapter 20, Integrating Data with a Visio Solution.
  • Transfer data from an external source You can set custom properties to use data from an external source, such as a spreadsheet or database, by writing a program that uses Automation to direct the flow of data. For details, see Chapter 20, Integrating Data with a Visio Solution.

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 (<b>A</b>) Shape with custom properties. (<b>B</b>) The value typed here is the value of the Prop.Cost cell.

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.

Defining Custom Properties

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 <b>Custom Properties</b> window.

Figure 7-9 You can enter new values for custom properties in the Custom Properties window.

To add custom properties to a shape, master, or page using the Custom Properties window

  1. On the View menu, click Custom Properties Window.
  2. Choose the shape, master, or page to which you want to add custom properties by selecting the shape on the page, selecting the shapes in a master in its drawing window, or clicking on the page.
  3. Note


    To edit a master in its window, make its stencil editable by opening it as Original. Then, right-click the master in its stencil and click Edit Master on the shortcut menu.

  4. Right-click in the Custom Properties window, and then click Define Properties on the shortcut menu
  5. In the Define Custom Properties dialog box, enter values for the settings that you want to use.
  6. Click New to add the custom property and continue adding more properties, or click OK to add the custom property and close the dialog box.

To add custom properties to a shape, master, or page using the ShapeSheet window

  1. Select a shape on the page, select the shapes in a master in its drawing window, or click an empty portion of the drawing page.
  2. Note


    To edit a master in its window, make its stencil editable by opening it as Original. Then, right-click the master in its stencil and click Edit Master on the shortcut menu.

  3. On the Window menu, click Show ShapeSheet.
  4. If the Custom Properties section is not already present, click Section on the Insert menu. In the Insert Section dialog box, select Custom Properties, and then click OK.
  5. In the Custom Properties section, select the Row label Prop.Row_1, which appears in red text. In the formula bar, type a descriptive name.
  6. 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.

  7. In the Label cell, type the label that appears to users in the Custom Properties window or dialog box for this property.
  8. For example, type Cost Per Unit. Visio automatically encloses the string in quotation marks.

  9. In the Prompt cell, type descriptive or instructional text that appears to users in the Custom Properties window or dialog box when the property is selected.
  10. For example, type Enter the cost per unit for the part. Visio automatically encloses the string in quotation marks.

  11. In the Type and Format cells, enter a data type and format for your custom property's value.
  12. For details, see the following table.

  13. Optional: Set the Invisible cell to a non-zero number ( true ) to prevent the custom property from appearing in the Custom Properties window or dialog box. Set the Ask cell to a non-zero number ( true ) to display the Custom Properties window or dialog box whenever an instance of the shape is created.
  14. 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).

Linking Custom Properties to a Database

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:

  • From a personnel database, you can generate an organization chart.
  • From a parts-specifications database, you can generate masters for your employees to use in drawings.
  • By connecting an inventory database to an office space plan, you can track furniture and equipment. If you delete a chair from the office plan, you also delete a record from the database.

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.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net