Attributes
A collection of named attribute dictionaries attached to a model or entity.
Attributes let extensions store custom key-value data on
models, faces, components, tags, and more. Data is organized
into named dictionaries — one per extension namespace. Use
getValue() to read a specific value, or allDictionaries
to see everything stored on the object.
To write or delete attributes, use
op.modelSetAttribute() or op.entitySetAttribute()
inside a performOperation.
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();
// Create a door group and store its price as an attributeawait model.performOperation(op => { const groupRef = op.createGroup(model); op.groupSetName(groupRef, 'Door'); op.createFace(groupRef, [ [0,0,0],[36,0,0], [36,0,84],[0,0,84], ]); // Use a unique namespace to avoid collisions // with other extensions op.entitySetAttribute( groupRef, 'MyPricingExtension', 'price', 299 );}, 'Create $299 door');
// Read the price backlet groups = await model.entities.get({ filterBy: { types: ['Group'] },});let door = groups.find(g => g.name === 'Door');let attrs = door.attributes;console.log( attrs.findValue('MyPricingExtension', 'price'));// => 299Accessors
Section titled “Accessors”dictionaries
Section titled “dictionaries”Get Signature
Section titled “Get Signature”get dictionaries(): readonly
AttributeDictionary[]
All dictionaries attached to this object. May contain duplicates when a model has been imported from another model.
SDK 2.35.0
Returns
Section titled “Returns”readonly AttributeDictionary[]
Methods
Section titled “Methods”findDictionary()
Section titled “findDictionary()”findDictionary(
name):AttributeDictionary|undefined
Finds a dictionary by name, returns undefined if not found
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
dictionary name to find |
Returns
Section titled “Returns”AttributeDictionary | undefined
SDK 2.35.0
findValue()
Section titled “findValue()”findValue<
T>(dictOrPath,key,options?):T
Finds the value at the dictOrPath with the given key
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
|
|
the expected return type — not verified at runtime |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
the dictionary name or a path to a dictionary |
|
|
|
the key |
|
|
{ |
allows to define a default value, stops this from throwing when the dictionary or key is not found |
|
|
|
‐ |
Returns
Section titled “Returns”T
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();let georeferenced = model.attributes.findValue('GeoReference','UsesGeoReferencing');// trueconsole.log(georeferenced);
let someNested = model.attributes.findValue(['Example', 'Nested'], 'Dictionary', {default: 123});// Default valuesconsole.log(someNested);
// error without defaultmodel.attributes.findValue(['Example', 'Nested'], 'Dictionary');Throws
Section titled “Throws”Error if a default value is not supplied
hasValue()
Section titled “hasValue()”hasValue(
dict,key):boolean
Determines if the dictionary and attribute key exist in this attributes object
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
the name or path of the dictionary |
|
|
|
the attribute key |
Returns
Section titled “Returns”boolean
true if the dictionary exists and the dictionary contains an attribute with the key
toString()
Section titled “toString()”toString():
string
Returns
Section titled “Returns”string
Deprecated
Section titled “Deprecated”allDictionaries
Section titled “allDictionaries”Get Signature
Section titled “Get Signature”get allDictionaries(): readonly
AttributeDictionary[]
All dictionaries attached to this object. May contain duplicates when a model has been imported from another model.
Returns
Section titled “Returns”readonly AttributeDictionary[]
getAttributesOfDictionary()
Section titled “getAttributesOfDictionary()”getAttributesOfDictionary(
dict):Attributes|undefined
Returns the nested Attributes of the named dictionary,
or undefined if the dictionary does not exist or has no
nested attributes.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Attributes | undefined
getValue()
Section titled “getValue()”getValue<
T>(dict,key):T
Returns the value for the given dictionary and key. Use
getValueOrDefault if you want a fallback instead of an
exception when the key is missing.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
|
|
the expected return type — not verified at runtime |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
the name of the dictionary |
|
|
|
the attribute key |
Returns
Section titled “Returns”T
Throws
Section titled “Throws”if the dictionary or key do not exist
getValueOrDefault()
Section titled “getValueOrDefault()”getValueOrDefault<
T>(dict,key,defaultValue):T
Returns the value for the given dictionary and key, or
defaultValue if the dictionary or key does not exist.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
|
|
the expected return type — not verified at runtime |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
the name of the dictionary |
|
|
|
the attribute key |
|
|
|
returned when the key is not found |
Returns
Section titled “Returns”T
getValueWithPath()
Section titled “getValueWithPath()”getValueWithPath<
T>(path,key):T
Returns the value found by traversing a path of nested dictionaries. Use when attributes are nested inside other dictionaries.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
|
|
the expected return type — not verified at runtime |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
non-empty list of dictionary names to traverse |
|
|
|
the attribute key at the final dictionary |
Returns
Section titled “Returns”T
Throws
Section titled “Throws”if any dictionary in the path or the key does not exist
getValueWithPathOrDefault()
Section titled “getValueWithPathOrDefault()”getValueWithPathOrDefault<
T>(path,key,defaultValue):T
Returns the value found by traversing a path of nested
dictionaries, or defaultValue if any step in the path or
the key does not exist.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
|
|
the expected return type — not verified at runtime |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
non-empty list of dictionary names to traverse |
|
|
|
the attribute key at the final dictionary |
|
|
|
returned when the path or key is not found |
Returns
Section titled “Returns”T
hasValueWithPath()
Section titled “hasValueWithPath()”hasValueWithPath(
path,key):boolean
Determines if all dictionaries in the path and the attribute key exist.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
a non-empty list of dictionary names to traverse |
|
|
|
the attribute key |
Returns
Section titled “Returns”boolean
true if the full path resolves and the key exists