Skip to content

Classifications

Only IFC 4 and IFC 2x3 supported at the moment

Section titled “Only IFC 4 and IFC 2x3 supported at the moment”
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async (operation) => {
const url = `https://cdn.habitat.sketchup.com/classifications/schemas/IFC2x3.skc`;
await operation.modelLoadSchemaFromUrl(url);
const classifications = await model.getClassifications();
console.log(classifications);
}, "Load a schema classification");
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async (operation) => {
const schemaName = "IFC 2x3";
await operation.modelUnloadSchema(schemaName);
const classifications = await model.getClassifications();
console.log(classifications);
}, "Unload a schema classification");
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async (operation) => {
const name = "classification";
const schemaType = "IfcDoor";
const schemaName = "IFC 2x3";
const componentRef = operation.createDefinition(name);
operation.definitionAddClassification(componentRef, schemaName, schemaType);
const classification = await operation
.entityForRef(componentRef)
.getClassifications(schemaName);
console.log(classification);
}, "Add a classification using a component ref");

Removing a classification to a componentRef

Section titled “Removing a classification to a componentRef”
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async (operation) => {
const name = "classification";
const schemaType = "IfcDoor";
const schemaName = "IFC 2x3";
const componentRef = operation.createDefinition(name);
operation.definitionRemoveClassification(componentRef, schemaName, schemaType);
const classification = await operation
.entityForRef(componentRef)
.getClassifications(schemaName);
console.log(classification);
}, "Remove a classification using a ref");
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async (operation) => {
const name = "classification";
const schemaType = "IfcDoor";
const schemaName = "IFC 2x3";
const path = ["ObjectType", "IfcLabel"];
const componentRef = operation.createDefinition(name);
operation.definitionAddClassification(componentRef, schemaName, schemaType);
const component = await operation.entityForRef(componentRef);
const classificationValue = component.getClassificationValue(
schemaName,
path
);
console.log(classificationValue);
}, "Get the classification value using a ref");
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async (operation) => {
const name = "classification";
const schemaType = "IfcDoor";
const schemaName = "IFC 2x3";
const pathToSet = ["ObjectType", "IfcLabel"];
const valueToSet = "Foo";
const componentRef = operation.createDefinition(name);
operation.definitionAddClassification(componentRef, schemaName, schemaType);
operation.definitionSetClassificationValue(
componentRef,
[schemaName, schemaType, ...pathToSet],
valueToSet
);
const component = await operation.entityForRef(componentRef);
const classificationValue = component.getClassificationValue(
schemaName,
pathToSet
);
console.log(classificationValue);
}, "Set the classification value using a ref");