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
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.' . |
Methods
load(defaultValues)
Load preference values from web storage/defaults.
Parameters
defaultValues* object | Preference names and their default values. |
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 |
remove(name, removeFromWebStorage)
Removes an existing preference.
Parameters
name* string | Preference name. |
removeFromWebStorage boolean | True to clear the web storage entry for this preference. |
Returns
type | description |
---|---|
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
type | description |
---|---|
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. |
Returns
type | description |
---|---|
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. |
removeListeners(name)
Remove listeners for preference changed and reset events.
Parameters
name* string | Preferences name. |