Request

Response

    Autodesk.Viewing.Private

    Preferences

    new Preferences(viewer, options)

    Application preferences.

    Optionally uses web storage.

    Each preference value can have tags associated to them. Developer supported tags are:

    ‘ignore-producer’ ‘no-storage’ ‘2d’ ‘3d’

    Use tag ‘ignore-producer’ in extensions to avoid having developer-defined render settings overridden by the loaded file.

    Use tag ‘no-storage’ in extensions to avoid having User Preferences (from Settings Panel) override default or developer-defined preferences. Useful for render settings.

    Preferences may apply to all model types, only 2D models (with tag ‘2d’) or 3D models only (with tag ‘3d’).

    Parameters

    Expand all
    viewer*
    Autodesk.Viewing.Viewer3D
    Viewer instance.
    options*
    object
    Contains configuration parameters used to do initializations.
    localStorage
    boolean
    Whether values get stored and loaded backfrom localStorage. Defaults to true.
    prefix
    string
    A string to prefix preference names in web storage.Defaults to 'Autodesk.Viewing.Preferences.'.
    * Required

    Methods

    load(defaultValues)

    Load preference values from web storage/defaults.

    Parameters

    defaultValues*
    object
    Preference names and their default values.
    * Required

    tag(tag, names)

    Adds a tag to the specified preferences. These are used by reset().

    Parameters

    untag(tag, names)

    Removes a tag from the specified preferences. These are used by reset().

    Parameters

    hasTag(name, tag)

    Checks whether a tag is associated to a name

    Parameters

    name*
    string
    Preference name
    tag*
    string
    The tag to check for
    * Required

    add(name, defaultValue, tags)

    Adds a new preference name + default value. This preference was not previously loaded via load().

    Parameters

    Returns

    typedescription
    boolean True if the preference was added.

    remove(name, removeFromWebStorage)

    Removes an existing preference.

    Parameters

    name*
    string
    Preference name.
    removeFromWebStorage
    boolean
    True to clear the web storage entry for this preference.
    * Required

    Returns

    typedescription
    boolean True if the preference was removed.

    reset(tag, include)

    Reset preferences to default values. If a tag is specified, then only certain preferences are reset.

    Parameters

    tag
    string
    Optional tag.
    include
    boolean
    True to reset only preferences with matching tags.

    get()

    Get named preference value. Shortcut: prefs[name]

    Returns

    typedescription
    Preference value.

    set(name, value, notify)

    Set named preference value. Value is not persisted if tag ‘no-storage’ is set. Do not use shortcut prefs[name] = value.

    Parameters

    name*
    string
    Preference name.
    value*
    Preference value.
    notify
    boolean
    If true then PREF_CHANGED_EVENT is fired.
    * Required

    Returns

    typedescription
    boolean True if the value changed, false otherwise.

    addListeners(name, onChangedCallback, onResetCallback)

    Listen for preference changed and reset events.

    Parameters

    name*
    string
    Preferences name.
    onChangedCallback*
    function
    Function called when preferences are changed.
    onResetCallback*
    function
    Function called when preferences are reset.
    * Required

    removeListeners(name)

    Remove listeners for preference changed and reset events.

    Parameters

    name*
    string
    Preferences name.
    * Required