Snap
A custom inference point that tools can snap to.
Snaps are like placing a magnet at a specific location and orientation in the model. Extensions use them to guide user interactions — for example, marking the center of a shape so that other tools can infer that point while drawing.
Example
Section titled “Example”// Create a circle with a snap at its centerlet model = await SketchUpApi.getActiveModel();let { Transformation } = SketchUpApi;
await model.performOperation(async op => { const groupRef = op.createGroup(model); op.groupSetName(groupRef, 'Snappable Circle');
// Draw a 20" radius circle inside the group op.createCircle( groupRef, [0, 0, 0], // center (group-local) [0, 0, 1], // normal (up) 20 // radius );
// Add a snap at the group's origin so tools // can infer the circle's center const snapRef = op.createSnap( groupRef, [0, 0, 0], // position (group-local) [0, 0, 1] // direction (up) );
// Move the group to [30, 30, 0] op.drawingElementsApplyTransformation( groupRef, Transformation.translation([30, 30, 0]) );
const snap = await op.entityForRef(snapRef); console.log(snap.position.x, snap.position.y); // => 0 0 (group-local coordinates)}, 'Create a circle with a snap at its center');SDK 2.20.0 Protocol 1.17.0
Extends
Section titled “Extends”BaseDrawingElement
Properties
Section titled “Properties”attributes
Section titled “attributes”
readonlyattributes:Attributes
The attribute dictionaries attached to this element. Attributes store custom key-value metadata that extensions can read and write.
Inherited from
Section titled “Inherited from”BaseDrawingElement.attributes
castsShadows
Section titled “castsShadows”
readonlycastsShadows:boolean
Whether this element casts shadows onto other geometry.
Inherited from
Section titled “Inherited from”BaseDrawingElement.castsShadows
direction
Section titled “direction”
readonlydirection:Vector3d
The direction this snap points, used to infer orientation.
hidden
Section titled “hidden”
readonlyhidden:boolean
Whether this element is hidden. Hidden elements don’t appear in the viewport unless the user enables “View > Hidden Geometry.”
Inherited from
Section titled “Inherited from”BaseDrawingElement.hidden
readonlyid:number
The persistent ID that uniquely identifies this snap.
materialRef
Section titled “materialRef”
readonlymaterialRef:MaterialRef|undefined
A reference to the material applied to this element, if any. Call
getMaterial() to fetch the full Material object with color and texture data.
Inherited from
Section titled “Inherited from”BaseDrawingElement.materialRef
position
Section titled “position”
readonlyposition:Point3d
The 3D coordinates of this snap in model space.
receivesShadows
Section titled “receivesShadows”
readonlyreceivesShadows:boolean
Whether this element receives shadows cast by other geometry.
Inherited from
Section titled “Inherited from”BaseDrawingElement.receivesShadows
tagRef
Section titled “tagRef”
readonlytagRef:TagRef|undefined
A reference to the tag (formerly “layer”) assigned to this element. Call
getTag() to fetch the full Tag object.
Inherited from
Section titled “Inherited from”BaseDrawingElement.tagRef
readonlytype:Snap=EntityType.Snap
readonlyup:Vector3d|undefined
The up vector for this snap, if one was specified.
Accessors
Section titled “Accessors”sketchupId
Section titled “sketchupId”Get Signature
Section titled “Get Signature”get sketchupId():
SketchupId
JS API identifier for this snap. Pass it to API methods that accept a sketchupId.
Returns
Section titled “Returns”Overrides
Section titled “Overrides”BaseDrawingElement.sketchupId
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”getBounds()
Section titled “getBounds()”getBounds():
Promise<BoundingBox>
Fetches the axis-aligned bounding box for this element from SketchUp.
Returns
Section titled “Returns”Promise<BoundingBox>
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();let all = await model.entities.get();let element = all[0];let box = await element.getBounds();console.log(box.min.x, box.min.y, box.min.z);console.log(box.max.x, box.max.y, box.max.z);SDK 2.30.0
Inherited from
Section titled “Inherited from”BaseDrawingElement.getBounds
getMaterial()
Section titled “getMaterial()”getMaterial():
Promise<Material|undefined>
Fetches the material applied to this element. Returns undefined if the
element uses the default material.
Returns
Section titled “Returns”Promise<Material | undefined>
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();let all = await model.entities.get();let element = all[0];let mat = await element.getMaterial();if (mat) { console.log(mat.name, mat.color.toHex());}SDK 2.30.0
Inherited from
Section titled “Inherited from”BaseDrawingElement.getMaterial
getTag()
Section titled “getTag()”getTag():
Promise<Tag|undefined>
Fetches the tag assigned to this element. Most elements have a tag — even
those on the default “Untagged” tag. Returns undefined only if the tag
reference is missing.
Returns
Section titled “Returns”Promise<Tag | undefined>
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();let all = await model.entities.get();let element = all[0];let tag = await element.getTag();if (tag) { console.log(tag.name);}SDK 2.30.0
Inherited from
Section titled “Inherited from”BaseDrawingElement.getTag
refresh()
Section titled “refresh()”refresh():
Promise<Snap>
Re-fetches this snap from SketchUp to get its current
state. Because Snap is a snapshot, it can become stale if
the model changes. Call refresh() to get an up-to-date
copy.
Returns
Section titled “Returns”Promise<Snap>
A new Snap reflecting the current model state. Throws if the snap has been deleted.
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();let snaps = await model.entities.get({ filterBy: { types: ['Snap'] },});// Later, after the user makes changes...let fresh = await snaps[0].refresh();console.log(fresh.position.x, fresh.position.y);toString()
Section titled “toString()”toString():
string
Returns a string representation of an object.
Returns
Section titled “Returns”string
Deprecated
Section titled “Deprecated”materialId
Section titled “materialId”
readonlymaterialId:number|undefined
Inherited from
Section titled “Inherited from”BaseDrawingElement.materialId
readonlytagId:number|undefined
Inherited from
Section titled “Inherited from”BaseDrawingElement.tagId
bounds
Section titled “bounds”Get Signature
Section titled “Get Signature”get bounds():
Promise<BoundingBox>
Returns
Section titled “Returns”Promise<BoundingBox>
Inherited from
Section titled “Inherited from”BaseDrawingElement.bounds
Get Signature
Section titled “Get Signature”get tag():
Promise<Readonly<Tag> |undefined>
Returns
Section titled “Returns”Promise<Readonly<Tag> | undefined>
Inherited from
Section titled “Inherited from”BaseDrawingElement.tag