class Dict

Bind to a Max dict object.

The Dict object lets you access structured data (a dictionary) associated with a name. If there is a named dict object in Max, it will share its contents with the JavaScript Dict object of the same name.

Index

Constructors

Properties

Methods

new Dict(name)

new Dict(name?: string);

Create a named dictionary

If no name is provided as an argument then a unique name will be generated for the dictionary.

ParameterTypeDescription
optional namestringname of the dictionary

append(key, values)

Add values to the associated data

Add values to the end of an array associated with the specified key.

append(key: string, ...values: any[]): void;
NameTypeDescription
keystringthe entry key
valuesany[]

clear()

Erase the contents of the dictionary, restoring to a clean state.

clear(): void;

clone(name)

Copy the named dictionary into this dictionary

clone(name: string): void;
NameTypeDescription
namestringname of the dictionary to copy

Example

var d1 = new Dict("one");
var d2 = new Dict("two");

d1.clone("two"); // Copies the dictionary named "two" into d1

contains(key)

Return a 0 or 1 indicating the specified key exists (or doesn't) in the dictionary.

contains(key: string): number;
NameTypeDescription
keystringname of the key to lookup
Return Valuenumber

export_json(filename)

Write a file in the JSON format.

export_json(filename: string): void;
NameTypeDescription
filenamestringName of the file to read

export_yaml(filename)

Write a file in the YAML format.

export_yaml(filename: string): void;
NameTypeDescription
filenamestringName of the file to read

freepeer()

Free the native C peer

Frees the dictionary data from the native C peer (created when making a Dict object), which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based JS allocated memory. Once called, the Dict object is not available for any other use. It's not necessary to call this function, as the memory will be freed eventually, but you can call it whenever you're done with your Dict object.

freepeer(): void;

get(key)

Return the value associated with a key.

get(key: string): any;
NameTypeDescription
keystringlookup key
Return Valueany

getkeys()

Return a list of all the keys in a dictionary, or null if the dictionary contains no keys.

getkeys(): string[] | null;
NameTypeDescription
Return Valuestring[] | null

getnames()

List of all named dictionaries.

Return a list of all the dictionary names that are known to Max.

getnames(): string[];
NameTypeDescription
Return Valuestring[]

getsize(key)

Length of the array of values associated with a key.

getsize(key: string): number;
NameTypeDescription
keystringThe key to look up
Return Valuenumber

gettype(key)

Type of the value or values associated with a key.

gettype(key: string): string;
NameTypeDescription
keystringThe key to look up
Return Valuestring

import_json(filename)

Read a file in the JSON format.

import_json(filename: string): void;
NameTypeDescription
filenamestringName of the file to read

import_yaml(filename)

Read a file in the YAML format.

import_yaml(filename: string): void;
NameTypeDescription
filenamestringName of the file to read

name string

The name of the dictionary

parse(serialization)

Parse a serialized dictionary and replace contents

Replaces the contents of the dictionary by parsing a dictionary serialization. Understands JSON and Max Dictionary Syntax

parse(serialization: string): void;
NameTypeDescription
serializationstringserialized dictionary string

pull_from_coll(coll_name)

Pull data from a named coll object

Adds entries to the dictionary by pulling rows from the given coll object. Does not clear existing keys from the dictionary.

pull_from_coll(coll_name: string): void;
NameTypeDescription
coll_namestringname of the coll object in Max

push_to_coll(coll_name)

Pull data into a named coll object

Push the dictionary's content into a named coll object. The keys in the dictionary will become the indices in the coll, and the values for those indices the values of the dictionary's keys.

push_to_coll(coll_name: string): void;
NameTypeDescription
coll_namestringname of the coll object in Max

quiet boolean

Suppresses many errors or warnings if set to true

readany(filename)

Loads the contents of a file.

Replaced the contents of the dictionary, clearing existing keys. Accepts JSON and YAML files.

readany(filename: string): void;
NameTypeDescription
filenamestringname of the file to load

remove(key)

Remove a key and its associated value from the dictionary.

remove(key: string): void;
NameTypeDescription
keystringthe key to remove

replace(key, value)

Set the value for a key to a specified value, creating a nested dicts if necessary.

Unlike Dict.set(), this function will create a hierarchical path to a given value if one does not already exist.

replace(key: string, ...value: any[]): void;
NameTypeDescription
keystringThe key or path to a dictionary entry
valueany[]The value or values to store at that path

Example

var d = new Dict(); // empty dictionary
d.replace("first::second::third", 42);
post(d.get("first").get("second").get("third")); // 42

set(key, value)

Set the value for a key to a specified value.

Unlike Dict.replace(), will not create nested dictionaryies if the nested structure does not already exist.

set(key: string, ...value: any[]): void;
NameTypeDescription
keystringThe key or path to a dictionary entry
valueany[]The value or values to store at that path

setparse(key, serialization)

Set the value for a key using a serialized dictionary

The serialization can be formatted as JSON or as Max Dictionary Syntax

setparse(key: string, serialization: string): void;
NameTypeDescription
keystringThe key or path to a dictionary entry
serializationstringWill be parsed to a dictionary and added to the Dict

stringify()

Return the content of the dictionary as a JSON string.

stringify(): string;
NameTypeDescription
Return Valuestring

stringify_compressed()

Return the content of the dictionary as a compressed JSON string.

stringify_compressed(): string;
NameTypeDescription
Return Valuestring

stringify_unformatted()

Return the content of the dictionary as an unformatted JSON string.

stringify_unformatted(): string;
NameTypeDescription
Return Valuestring

writeagain()

Open a save dialog to write the dictionary contents to a file.

writeagain(): void;