The Open method opens a document as an original (that is, for read/write access), which is not good for stencils and templates, because you probably don’t want your users changing those.
Use OpenEx with the appropriate flag to open a file as read-only. Open a stencil docked in a drawing window, or open a file without adding it to Visio’s file menu of most recently used files.
For best results, try to use a full path when opening a document. Using relative path names can be unpredictable at times. Do not hard code the path but instead use the common Open dialog box to get the user to indicate the path. Under some circumstances you might be able to construct the path from the Path property of a document that is already open.
If the document you want is already open, you can get it by its filename or its index in the collection.
Noteworthy Document Properties
These are a few of the Document object properties available through the object model. You’ve already see the Masters and Pages collections, but a Document object also has Styles, Fonts, Colors, and Visual Basic Project collections, with objects that represent those items.
The Name, Fullname, and Path properties contain the short filename, full filename, and just the path portion of a document’s full filename, respectively.
Description, Keywords, Subject, and Title correspond to options of the same name in the document’s summary information. (Properties command from the File menu.) Creator corresponds to Author in the File Properties dialog.
ReadOnly, Saved, and InPlace are Boolean properties that indicate whether a document was opened as read-only, has been changed since it was opened (the Saved property is really a dirty flag) or has been opened for in-place editing in a container document rather than in a standalone instance of Visio.
To determine whether a document has been saved, check its Path property. If an existing document has been opened or a new document has been saved, its Path property will be set.
TimeCreated, TimeEdited, TimeSaved and TimePrinted return the date and time of each action. The return value is a date formatted like this one:
4/6/10 1:50:21 PM
There are several Print… properties that allow you to set properties for printed output, such as Printer, PrintCenteredH, PrintPagesDown, PrintFitOnPages, etc. Set these properties first and then use the Print method to print your document.
Getting a page is similar to getting an open document; you can get the page by its name or by its index in the Pages collection.
The ActivePage property is a quick way of getting a page without going through a document. However, it only works if the active window is a drawing window. If a stencil window had focus and you attempted to get the ActivePage, an error would occur in your solution.
This will make more sense a little bit later in the session, when you learn about windows and the selection object.
We have already seen that a Page has a Shapes property for accessing the shape collection on the page. The Page also has a Layers property for accessing information about Layers defined for the page and a Connects property for getting information about connections that exist on the page.
You’ve already worked with shapes and used some of their properties, such as Text and Cells.
When you’re working with shapes from a program, the definition is somewhat expanded. A page’s Shapes collection includes basic shapes, groups, guides and guide points, and linked or embedded objects (bitmaps, metafiles, Excel spreadsheets, and so forth.).
Obviously, these various items differ quite a bit in what you can do with them. So if you’re iterating through a Shapes collection, you’ll almost always want to check a shape’s type before continuing with whatever you’re doing to the shape. The Type property of a Shape object returns a constant describing the shape.
Recall getting the PageSheet property in the last session. That property returns a Shape object so you can use its Cells property to get page formulas. If you check that Shape object’s Type property, it returns visTypePage.
A few interesting Shape properties include AreaIU, which returns the area of the shapes geometry in internal units, Characters, which contains the shapes text and the fields that control that text, Connects and FromConnects, which contain shape connection information, and Layer, which contains information about the layers a shape is assigned to.
Getting Data About Connections
Earlier you saw how to connect shapes in a drawing through Automation.
The relationship between a shape and the object that it is glued to is represented by a Connect object.
Every shape has a Connects collection. If the shape isn’t glued to anything, the collection is empty.
If the shape is glued to one other shape (or guide), its Connects collection contains one Connect object representing that relationship. You access the Connects collection differently depending upon whether the shape is a one-dimensional or two-dimensional shape.
You can get information about the connection by getting properties of the Connect object.
-
The FromSheet and ToSheet properties return Shape objects for the shapes involved in the connection.
-
The FromPart and ToPart properties return integers that indicate which parts of the shapes are involved. These are represented by constants such as visControlPoint and visConnectionPoint.
-
The FromCell and ToCell properties return Cell objects that correspond to the FromPart and ToPart values.
For example, if FromPart is visControlPoint, FromCell returns a Cell object that represents that control handle in the ShapeSheet.
Share with your friends: |