Skip to content

Face

let model = await SketchUpApi.getActiveModel();
await model.performOperation(async operation => {
const faceRef = operation.createFace(operation.model, [
[0, 0, 0],
[10, 0, 0],
[10, 10, 0],
[0, 10, 0],
]);
console.log(await operation.entityForRef(faceRef));
}, 'Create a face');
let model = await SketchUpApi.getActiveModel();
await model.performOperation(operation => {
const faceRef = operation.createFace(operation.model, [
[0, 0, 0],
[10, 0, 0],
[10, 10, 0],
[0, 10, 0],
]);
return operation.drawingElementEraseWithForce(faceRef);
}, 'removing face');
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async operation => {
const faceRef = operation.createFace(operation.model, [
[0, 0, 0],
[10, 0, 0],
[10, 10, 0],
[0, 10, 0],
]);
const tagRef = operation.createTag('Some Tag');
const tag = await operation.entityForRef(tagRef);
let face = await operation.entityForRef(faceRef);
console.log("Face.tagId before: ", face.tagId);
operation.drawingElementSetTag(face, tag);
console.log("Tag.id: ", tag.id);
face = await face.refresh();
console.log("Face.tagId after: ", face.tagId);
}, 'Creating a Face and assign a Tag');
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async operation => {
const materialRef = operation.createMaterial('32 bit img with 4 colors');
operation.materialSetTextureImageRep(materialRef,
{
width: 2,
height: 2,
bitsPerPixel: 32,
rowPadding: 0,
imageData: '\xFF\x00\x00\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00'
}
);
const faceRef = operation.createFace(operation.model, [
[50, 0, -10],
[100, 0, -10],
[100, 50, -10],
[50, 50, -10],
]);
operation.faceSetFrontMaterial(faceRef, materialRef);
operation.faceSetBackMaterial(faceRef, materialRef);
}, 'Creating a face and Setting a material');
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async operation => {
const faceRef = await operation.createFace(operation.createGroup(operation.model), [
[0, 0, 0],
[0, 1, 1],
[0, 1, 0],
]);
const facesBeforePushPull = await operation.model.getNumberOfFaces();
console.log("Faces before: ", facesBeforePushPull);
operation.facePushPull(faceRef, 100, true);
console.log("Faces after: ", await operation.model.getNumberOfFaces());
}, 'PushPull a Face');
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async operation => {
// Create a circle, which returns the arc curve and its edges
const { curve, edges } = operation.createCircle(
operation.model,
[0, 0, 0], // center point
[0, 0, 1], // normal vector (pointing up in Z)
50, // radius
24 // number of segments
);
// Create a face from the circle's edges
const faceRef = operation.createFaceFromEdges(operation.model, edges);
const face = await operation.entityForRef(faceRef);
console.log("Created face with area:", await face.getArea());
}, 'Create face from circle edges');
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async operation => {
// Create a material with a texture
const materialRef = operation.createMaterial('Textured Material');
operation.materialSetTextureImageRep(
materialRef,
{
width: 2,
height: 2,
bitsPerPixel: 32,
rowPadding: 0,
imageData: '\xFF\x00\x00\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00'
}
);
// Create a face and apply the material
const faceRef = operation.createFace(operation.model, [
[0, 0, 0],
[100, 0, 0],
[100, 100, 0],
[0, 100, 0],
]);
operation.faceReverse(faceRef);
operation.faceSetFrontMaterial(faceRef, materialRef);
const face = await operation.entityForRef(faceRef);
// Get UV coordinates for specific points on the face
const uvResponse = await face.getUVs({
front: [
[0, 0, 0], // bottom-left corner
[50, 50, 0], // center point
[100, 100, 0], // top-right corner
]
});
// Log the UV coordinates (u, v, q values)
uvResponse.front.forEach((uvMap, i) => {
console.log(`Point ${i}:`, uvMap.point, '-> UV:', uvMap.uv);
});
}, 'Get UV coordinates from face');
let model = await SketchUpApi.getActiveModel();
await model.performOperation(async operation => {
// Create a material with a texture
const materialRef = operation.createMaterial('Tiled Material');
operation.materialSetTextureImageRep(
materialRef,
{
width: 2,
height: 2,
bitsPerPixel: 32,
rowPadding: 0,
imageData: '\xFF\x00\x00\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00\xFF\xFF\xFF\xFF\x00'
}
);
// Create a face
const faceRef = operation.createFace(operation.model, [
[0, 0, 0],
[200, 0, 0],
[200, 200, 0],
[0, 200, 0],
]);
operation.faceReverse(faceRef);
operation.faceSetFrontMaterial(faceRef, materialRef);
const face = await operation.entityForRef(faceRef);
// Get UV tile information for points on the face
const uvTileResponse = await face.getUVTiles({
front: [
[50, 50, 0],
[150, 150, 0],
]
});
// Each tile contains corner UV coordinates
uvTileResponse.front.forEach((tile, i) => {
if (tile) {
console.log(`Tile ${i} has ${tile.length} corners`);
tile.forEach(corner => {
console.log(' Corner:', corner.point, '-> UV:', corner.uv);
});
}
});
}, 'Get UV tile information');