Texture
The image data behind a textured material.
When a material has an image applied (rather than just a solid
color), its texture property holds a Texture instance. The
Texture tells you the image dimensions in both pixel space
(imageWidth/imageHeight) and model space
(width/height in inches), and lets you export the image
data for use outside SketchUp.
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();let materials = await model.getMaterials();
// Find a textured materiallet textured = materials.values.find( m => m.texture !== undefined);if (textured) { const tex = textured.texture; console.log(tex.imageWidth, tex.imageHeight); // => pixel dimensions (e.g. 512 512) console.log(tex.width, tex.height); // => model-space size in inches}SDK 2.12.0 Protocol 1.9.0
Properties
Section titled “Properties”attributes
Section titled “attributes”
readonlyattributes:Attributes
Custom attribute dictionaries attached to this texture.
readonlycolor:Color
The average color of this texture image.
height
Section titled “height”
readonlyheight:number
Physical height of the texture in the model, in inches.
readonlyid:number
The persistent ID that uniquely identifies this texture.
imageHeight
Section titled “imageHeight”
readonlyimageHeight:number
Height of the source image in pixels.
imageWidth
Section titled “imageWidth”
readonlyimageWidth:number
Width of the source image in pixels.
readonlytype:Texture=EntityType.Texture
readonlywidth:number
Physical width of the texture in the model, in inches.
Accessors
Section titled “Accessors”sketchupId
Section titled “sketchupId”Get Signature
Section titled “Get Signature”get sketchupId():
SketchupId
JS API identifier for this texture. Pass it to API methods that accept a sketchupId.
Returns
Section titled “Returns”typeName
Section titled “typeName”Get Signature
Section titled “Get Signature”get typeName():
string
Returns a named variant of the type field.
SDK 2.35.0
Returns
Section titled “Returns”string
Methods
Section titled “Methods”getImage()
Section titled “getImage()”getImage(
fileType,options?):Promise<string>
Exports the texture image as a base64-encoded string in the specified format. Use this to download or display the texture outside of SketchUp.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
|
|
|
export options (e.g. colorize settings) |
Returns
Section titled “Returns”Promise<string>
SDK 2.30.3 Protocol 1.9.0
refresh()
Section titled “refresh()”refresh():
Promise<Texture>
Re-fetches this texture from SketchUp to get its current state (dimensions or color may have changed).
Returns
Section titled “Returns”Promise<Texture>
toString()
Section titled “toString()”toString():
string
Returns
Section titled “Returns”string
Deprecated
Section titled “Deprecated”export()
Section titled “export()”export(
fileType,options?):Promise<string>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
Returns
Section titled “Returns”Promise<string>
SDK 2.12.0 Protocol 1.9.0