Visio.Document class

Represents the Document class.

[ API set: 1.1 ]

Extends

Properties

application

Represents a Visio application instance that contains this document. Read-only.

[ API set: 1.1 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

pages

Represents a collection of pages associated with the document. Read-only.

[ API set: 1.1 ]

view

Returns the DocumentView object. Read-only.

[ API set: 1.1 ]

Methods

getActivePage()

Returns the Active Page of the document.

[ API set: 1.1 ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

setActivePage(PageName)

Set the Active Page of the document.

[ API set: 1.1 ]

startDataRefresh()

Triggers the refresh of the data in the Diagram, for all pages.

[ API set: 1.1 ]

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Visio.Document object is an API object, the toJSON method returns a plain JavaScript object (typed as Visio.Interfaces.DocumentData) that contains shallow copies of any loaded child properties from the original object.

Events

onDataRefreshComplete

Occurs when the data is refreshed in the diagram.

[ API set: 1.1 ]

onDocumentLoadComplete

Occurs when the Document is loaded, refreshed, or changed.

[ API set: 1.1 ]

onPageLoadComplete

Occurs when the page is finished loading.

[ API set: 1.1 ]

onSelectionChanged

Occurs when the current selection of shapes changes.

[ API set: 1.1 ]

onShapeMouseEnter

Occurs when the user moves the mouse pointer into the bounding box of a shape.

[ API set: 1.1 ]

onShapeMouseLeave

Occurs when the user moves the mouse out of the bounding box of a shape.

[ API set: 1.1 ]

Property Details

application

Represents a Visio application instance that contains this document. Read-only.

[ API set: 1.1 ]

readonly application: Visio.Application;

Property Value

Visio.Application

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

RequestContext

pages

Represents a collection of pages associated with the document. Read-only.

[ API set: 1.1 ]

readonly pages: Visio.PageCollection;

Property Value

Visio.PageCollection

Examples

Visio.run(session, function (ctx) {
    var pages = ctx.document.pages;
    var pageCount = pages.getCount();
    return ctx.sync().then(function () {
        console.log("Pages Count: " +pageCount.value);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

view

Returns the DocumentView object. Read-only.

[ API set: 1.1 ]

readonly view: Visio.DocumentView;

Property Value

Method Details

getActivePage()

Returns the Active Page of the document.

[ API set: 1.1 ]

getActivePage(): Visio.Page;

Returns

Visio.Page

Examples

Visio.run(session, function (ctx) {
    var document = ctx.document;
    var activePage = document.getActivePage();
    activePage.load("name");
    return ctx.sync().then(function () {
        console.log("pageName: " +activePage.name);
    });   
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: Visio.Interfaces.DocumentLoadOptions): Visio.Document;

Parameters

Returns

Visio.Document

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Visio.Document - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Visio.Document - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Visio.Document - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Visio.Document;

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

Visio.Document

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: { select?: string; expand?: string; }): Visio.Document;

Parameters

propertyNamesAndPaths
{ select?: string; expand?: string; }

Where propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

Visio.Document

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties: Interfaces.DocumentUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameters

properties
Interfaces.DocumentUpdateData

A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

Provides an option to suppress errors if the properties object tries to set any read-only properties.

Returns

void

Remarks

This method has the following additional signature:

set(properties: Visio.Document): void

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Visio.Document): void;

Parameters

properties
Visio.Document

Returns

void

setActivePage(PageName)

Set the Active Page of the document.

[ API set: 1.1 ]

setActivePage(PageName: string): void;

Parameters

PageName
string

Name of the page

Returns

void

Examples

Visio.run(session, function (ctx) {
    var document = ctx.document;
    var pageName = "Page-1";
    document.setActivePage(pageName);
    return ctx.sync();
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

startDataRefresh()

Triggers the refresh of the data in the Diagram, for all pages.

[ API set: 1.1 ]

startDataRefresh(): void;

Returns

void

Examples

Visio.run(session, function (ctx) {
    var document = ctx.document;
    document.startDataRefresh();
    return ctx.sync();
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Visio.Document object is an API object, the toJSON method returns a plain JavaScript object (typed as Visio.Interfaces.DocumentData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Visio.Interfaces.DocumentData;

Returns

Event Details

onDataRefreshComplete

Occurs when the data is refreshed in the diagram.

[ API set: 1.1 ]

readonly onDataRefreshComplete: OfficeExtension.EventHandlers<Visio.DataRefreshCompleteEventArgs>;

Returns

OfficeExtension.EventHandlers<Visio.DataRefreshCompleteEventArgs>

onDocumentLoadComplete

Occurs when the Document is loaded, refreshed, or changed.

[ API set: 1.1 ]

readonly onDocumentLoadComplete: OfficeExtension.EventHandlers<Visio.DocumentLoadCompleteEventArgs>;

Returns

OfficeExtension.EventHandlers<Visio.DocumentLoadCompleteEventArgs>

onPageLoadComplete

Occurs when the page is finished loading.

[ API set: 1.1 ]

readonly onPageLoadComplete: OfficeExtension.EventHandlers<Visio.PageLoadCompleteEventArgs>;

Returns

OfficeExtension.EventHandlers<Visio.PageLoadCompleteEventArgs>

onSelectionChanged

Occurs when the current selection of shapes changes.

[ API set: 1.1 ]

readonly onSelectionChanged: OfficeExtension.EventHandlers<Visio.SelectionChangedEventArgs>;

Returns

OfficeExtension.EventHandlers<Visio.SelectionChangedEventArgs>

onShapeMouseEnter

Occurs when the user moves the mouse pointer into the bounding box of a shape.

[ API set: 1.1 ]

readonly onShapeMouseEnter: OfficeExtension.EventHandlers<Visio.ShapeMouseEnterEventArgs>;

Returns

OfficeExtension.EventHandlers<Visio.ShapeMouseEnterEventArgs>

onShapeMouseLeave

Occurs when the user moves the mouse out of the bounding box of a shape.

[ API set: 1.1 ]

readonly onShapeMouseLeave: OfficeExtension.EventHandlers<Visio.ShapeMouseLeaveEventArgs>;

Returns

OfficeExtension.EventHandlers<Visio.ShapeMouseLeaveEventArgs>