Visio.Document class

Represents the Document class.

Extends

Remarks

[ API set: 1.1 ]

Properties

application

Represents a Visio application instance that contains this document.

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.

view

Returns the DocumentView object.

Methods

getActivePage()

Returns the Active Page of the document.

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.

setMockData(data)

Set mock data

showTaskPane(taskPaneType, initialProps, show)

Shows or hides 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.

showTaskPane(taskPaneTypeString, initialProps, show)

Shows or hides 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.

startDataRefresh()

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

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.

onDocumentError

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

onDocumentLoadComplete

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

onPageLoadComplete

Occurs when the page is finished loading.

onSelectionChanged

Occurs when the current selection of shapes changes.

onShapeMouseEnter

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

onShapeMouseLeave

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

onTaskPaneStateChanged

Occurs whenever a task pane state is changed.

Property Details

application

Represents a Visio application instance that contains this document.

readonly application: Visio.Application;

Property Value

Remarks

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

context: RequestContext;

Property Value

pages

Represents a collection of pages associated with the document.

readonly pages: Visio.PageCollection;

Property Value

Remarks

[ API set: 1.1 ]

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.

readonly view: Visio.DocumentView;

Property Value

Remarks

[ API set: 1.1 ]

Method Details

getActivePage()

Returns the Active Page of the document.

getActivePage(): Visio.Page;

Returns

Remarks

[ API set: 1.1 ]

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

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.

setActivePage(PageName: string): void;

Parameters

PageName

string

Name of the page

Returns

void

Remarks

[ API set: 1.1 ]

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)

Shows or hides 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.

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 task pane.

show

boolean

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

Returns

void

Remarks

[ API set: 1.1 ]

showTaskPane(taskPaneTypeString, initialProps, show)

Shows or hides 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.

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 task pane.

show

boolean

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

Returns

void

Remarks

[ API set: 1.1 ]

startDataRefresh()

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

startDataRefresh(): void;

Returns

void

Remarks

[ API set: 1.1 ]

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.

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

Event Type

Remarks

[ API set: 1.1 ]

onDocumentError

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

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

Event Type

Remarks

[ API set: 1.1 ]

onDocumentLoadComplete

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

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

Event Type

Remarks

[ API set: 1.1 ]

onPageLoadComplete

Occurs when the page is finished loading.

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

Event Type

Remarks

[ API set: 1.1 ]

onSelectionChanged

Occurs when the current selection of shapes changes.

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

Event Type

Remarks

[ API set: 1.1 ]

onShapeMouseEnter

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

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

Event Type

Remarks

[ API set: 1.1 ]

onShapeMouseLeave

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

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

Event Type

Remarks

[ API set: 1.1 ]

onTaskPaneStateChanged

Occurs whenever a task pane state is changed.

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

Event Type

Remarks

[ API set: 1.1 ]