Skip to content

ComponentDefinitionRef

A lightweight placeholder for a ComponentDefinition that hasn’t been fully loaded yet.

When you create a component definition inside a SketchupOperation, the API returns a ComponentDefinitionRef immediately, before SketchUp has finished processing it. You can pass these refs to other operation methods (like adding geometry to the definition or creating instances), but if you need the full ComponentDefinition instance, you can request it with entityForRef().

Think of a ref as a “claim ticket” — it guarantees a component definition will exist after the operation commits, but it doesn’t carry the definition’s properties (name, entities, instances, etc.) yet. A ref is only valid inside the performOperation callback that created it — do not return it or use it after the operation commits.

let model = await SketchUpApi.getActiveModel();
let { Transformation } = SketchUpApi;
await model.performOperation(async op => {
const defRef = op.createDefinition('Table');
// Add a tabletop face to the definition
op.createFace(defRef, [
[0, 0, 30], [48, 0, 30],
[48, 30, 30], [0, 30, 30],
]);
// Place an instance so it's visible
op.createInstance(
model, defRef, Transformation.translation([0, 0, 0])
);
const def = await op.entityForRef(defRef);
console.log(def.name);
// => "Table"
}, 'Create a table component');

readonly sketchupId: SketchupId


readonly type: Component = EntityType.ComponentDefinition

get typeName(): string

Returns a named variant of the type field.

SDK 2.35.0

string