Request

Response

    Core

    Autodesk.Viewing.Extension

    new Extension(viewer,options)

    Base class for extending the functionality of the viewer.

    Derive from this class and implement the load and optionally the unload methods.

    Register this extension by calling: Autodesk.Viewing.theExtensionManager.registerExtension('your_extension_id', Autodesk.Viewing.Extensions.<your_extension_class>);

    Extensions are registered and loaded automatically by adding the Extension ID to the config object passed to the viewer constructor.

    An example Extension is available at modelderivative/v2/viewers/SampleExtension/, and includes these files:

    • SampleExtension.js
    • SampleLayersPanel.js
    • SampleModelStructurePanel.js
    • SamplePropertyPanel.js
    • SampleLayersPanel.css
    • SampleModelStructurePanel.css
    • SamplePropertyPanel.css

    Parameters

    viewer*The viewer to be extended.
    options*
    object
    An optional dictionary of options for this extension.
    * Required

    Methods

    extendLocalization(locales)

    Override the set of localized strings

    Parameters

    locales*
    object
    The set of localized strings keyed by language
    * Required

    Returns

    TypeDescription
    boolean True if localization was successfully updated

    getCache()

    Returns an object that persists throughout an extension’s unload->load operation sequence. Cache object is kept at ViewingApplication level. Cache object lives only in RAM, there is no localStorage persistence.

    Returns

    TypeDescription
    object The cache object for a given extension.

    getState(viewerState)

    Gets the extension state as a plain object. Intended to be called when viewer state is requested.

    Parameters

    viewerState*
    object
    Object to inject extension values.
    * Required

    load()

    Override the load method to add functionality to the viewer. Use the Viewer’s APIs to add/modify/replace/delete UI, register event listeners, etc.

    Returns

    TypeDescription
    boolean True if the load was successful.

    restoreState(viewerState,immediate)

    Restores the extension state from a given object.

    Parameters

    viewerState*
    object
    Viewer state.
    immediate*
    boolean
    Whether the new view is applied with (true) or without transition (false).
    * Required

    Returns

    TypeDescription
    boolean True if restore operation was successful.

    unload()

    Override the unload method to perform some cleanup of operations that were done in load.

    Returns

    TypeDescription
    boolean True if the unload was successful.