Volume 3: Programming with the Visio Object Model disclaimer



Download 0.78 Mb.
Page10/36
Date29.01.2017
Size0.78 Mb.
#11974
1   ...   6   7   8   9   10   11   12   13   ...   36

CALLTHIS


Even though RUNADDON is a very powerful function, there are times where the add-on being executed needs to get a reference to the shape that initiated the action.

CALLTHIS is a variation of RUNADDON that automatically passes a reference to the shape that caused the add-on to be executed. Notice that the reference to the shape is very much like the "this" argument passed to a C++ member procedure; hence, the name "CALLTHIS."

In effect, a cell that contains a formula with CALLTHIS is saying, "Call procedure and pass it a reference to my shape."

The demonstration file CallThis.vsd has some good examples of using the CALLTHIS function.

Where to Find Visio Automation Information


There are many ways to get helpful information on the Visio automation model. A good place to start is with the Visio help files. The Developer Reference help file contains material for the automation model. Help information for the ShapeSheet is contained in the Visio SDK.


Demonstration: Developer Reference

  1. Open the Developer Reference help file, Help > Search > Developer Reference.

  2. In the Table of Contents select Visio Automation Object Model Reference.

  3. Display an object topic. This describes the object and lists its properties and methods.

  4. Display the topic for one of the object’s methods. Review what is in each property and method topic.

  5. Use some of the other jumps in the method topic to related properties and methods or other objects that have the same method.

Other sources of information include the Visio Developer Portal on msdn.microsoft.com. This is the key entry point to gaining access to the latest articles, examples and downloads related to Visio.

There are also Visio discussion groups where you can post questions and get answers.

http://www.microsoft.com/communities/newsgroups/en-us/

The Visio SDK provides sample applications, code librarian code snippets, documentation, and tools—including the Event Monitor, Persistent Events, Print ShapeSheet, and Solution Publishing.

A great way to explore the object model and really get a feel for how everything ties together is through the Object Browser. From the Visual Basic Editor choose View > Object Browser to display the Object Browser window. From the Object Browser you can explore the entire Visio Object Model.

You can also explore a live Visio application by using the Immediate window from VBE. Choose View > Immediate Window. From the Immediate window investigate objects, properties, and methods of the current running instance of Visio.

The Watch Window and the Locals Window are great places to view data values when exercising or debugging code in VBA.

The Macro Recorder can be used to develop snippets of code for performing some function in Visio. Turn on the Macro recorder, perform the function you wish to automate, and then turn off the recorder. Viewing the generated code will show you how the operation is performed through automation.

There are, however, limitations on the actions that can be captured by the Macro Recorder. Dialog only commands and Solution-specific commands are generally not recorded - so you could not automate the dropping and property setting of Database Model entities, for example. Also, you cannot record the action of shutting down the application, or any actions which leave Visio in a Modal state. The API programmability model for Themes, Data Graphics, and Pivot diagrams does not cover everything that can be done in the user interface so use of the macro recorder in these areas has been short circuited.


Lab 3.2: Running VB Add-ons


For the lab, follow the directions listed on the slide.



Note:

Check File > Options > Advanced > File Locations for the appropriate add-on folder.



Review: Automation and Visio



Questions


  1. What are some of the objects in Visio’s object model? How might you use them in a program?

  2. Once you’ve finished building your custom solution, what are some of the different ways you can run it?

  3. How might this influence the design of your program?



Answers


  1. Application, Document, Shape, Window, Cell, etc. Visio drawings can be created using automation or existing drawings can be interrogated for information.

  2. Solutions can be set up to run from a shape with a right-click action or a double-click. Add-ins and macros can also be executed from the View tab of the ribbon.

  3. A fundamental decision is between creating a macro and creating an add-in. Macros are useful for fairly simple one-off type solutions.

8.

Generating Drawings


In this section let’s begin by using automation to create a document, drop masters in a drawing, and set the text of shapes.

Along the way you’ll see more generally how to get and set shape properties, including how to access a particular formula and get either the formula as a string, or the value that is its result.



Download 0.78 Mb.

Share with your friends:
1   ...   6   7   8   9   10   11   12   13   ...   36




The database is protected by copyright ©ininet.org 2024
send message

    Main page