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(options)

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 ]

setMockData(data)

Set mock data

showTaskPane(taskPaneType, initialProps, show)

Show or Hide a TaskPane. This will be consumed by the DV Excel Add-In/Other third-party apps who embed the visio drawing to show/hide the task pane.

[ API set: 1.1 ]

showTaskPane(taskPaneTypeString, initialProps, show)

Show or Hide a TaskPane. This will be consumed by the DV Excel Add-In/Other third-party apps who embed the visio drawing to show/hide the task pane.

[ 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 ]

onDocumentError

Occurs when there is an expected or unexpected error occured in the session.

[ 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 ]

onTaskPaneStateChanged

Occurs whenever a task pane state is changed

[ 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

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

pages

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

[ API set: 1.1 ]

readonly pages: Visio.PageCollection;

Property Value

Examples

Visio.run(session, function (ctx) {
    const pages = ctx.document.pages;
    const 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

Examples

Visio.run(session, function (ctx) {
    const document = ctx.document;
    const 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(options)

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

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

Parameters

options
Visio.Interfaces.DocumentLoadOptions

Provides options for which properties of the object to load.

Returns

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

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; }

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

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
Visio.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) {
    const document = ctx.document;
    const 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));
    }
});

setMockData(data)

Set mock data

setMockData(data: Visio.Interfaces.DocumentData): void;

Parameters

Returns

void

showTaskPane(taskPaneType, initialProps, show)

Show or Hide a TaskPane. This will be consumed by the DV Excel Add-In/Other third-party apps who embed the visio drawing to show/hide the task pane.

[ API set: 1.1 ]

showTaskPane(taskPaneType: Visio.TaskPaneType, initialProps?: any, show?: boolean): void;

Parameters

taskPaneType
Visio.TaskPaneType

Type of the 1st Party TaskPane. It can take values from enum TaskPaneType

initialProps

any

Optional Parameter. This is a generic data structure which would be filled with initial data required to initialize the content of the Taskpane

show

boolean

Optional Parameter. If it is set to false, it will hide the specified taskpane

Returns

void

showTaskPane(taskPaneTypeString, initialProps, show)

Show or Hide a TaskPane. This will be consumed by the DV Excel Add-In/Other third-party apps who embed the visio drawing to show/hide the task pane.

[ API set: 1.1 ]

showTaskPane(taskPaneTypeString: "None" | "DataVisualizerProcessMappings" | "DataVisualizerOrgChartMappings", initialProps?: any, show?: boolean): void;

Parameters

taskPaneTypeString

"None" | "DataVisualizerProcessMappings" | "DataVisualizerOrgChartMappings"

Type of the 1st Party TaskPane. It can take values from enum TaskPaneType

initialProps

any

Optional Parameter. This is a generic data structure which would be filled with initial data required to initialize the content of the Taskpane

show

boolean

Optional Parameter. If it is set to false, it will hide the specified taskpane

Returns

void

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) {
    const 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>;

Event Type

onDocumentError

Occurs when there is an expected or unexpected error occured in the session.

[ API set: 1.1 ]

readonly onDocumentError: OfficeExtension.EventHandlers<Visio.DocumentErrorEventArgs>;

Event Type

onDocumentLoadComplete

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

[ API set: 1.1 ]

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

Event Type

onPageLoadComplete

Occurs when the page is finished loading.

[ API set: 1.1 ]

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

Event Type

onSelectionChanged

Occurs when the current selection of shapes changes.

[ API set: 1.1 ]

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

Event Type

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>;

Event Type

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>;

Event Type

onTaskPaneStateChanged

Occurs whenever a task pane state is changed

[ API set: 1.1 ]

readonly onTaskPaneStateChanged: OfficeExtension.EventHandlers<Visio.TaskPaneStateChangedEventArgs>;

Event Type