Group
Creating a Group and setting a name, description, lock
Section titled “Creating a Group and setting a name, description, lock”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const groupRef = operation.createGroup(model); operation.groupSetName(groupRef, 'A Group'); operation.groupSetDescription(groupRef, 'This is an example Group'); operation.groupSetLocked(groupRef, true); const group = await operation.entityForRef(groupRef);
console.log("Group.name: ",group.name); console.log("Group.description: ",group.description); console.log("Group.locked: ",group.locked);}, 'Creating a group');Assign a Tag to a Group
Section titled “Assign a Tag to a Group”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { // Setup a group and tag const groupRef = operation.createGroup(model); const tagRef = operation.createTag('Some Tag'); operation.groupSetName(groupRef, 'A Group on a Tag');
// Get the group from SketchUp let group = await operation.entityForRef(groupRef); console.log("Group.tagId before: ", group.tagId);
// Reassign the tag operation.drawingElementSetTag(group, tagRef); console.log("Tag.id: ", tag.id);
// Refetch and verify that the tag has changed. group = await group.refresh(); console.log("Group.tagId after: ", group.tagId);}, 'Creating a Group and assign a Tag');Adding an Edge to a Group
Section titled “Adding an Edge to a Group”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const groupRef = operation.createGroup(model); operation.groupSetName(groupRef, 'A Group with an Edge'); const group = await operation.entityForRef(groupRef); let edges = await group.entities.get({ filterBy: { types: ['Edge'] } }); console.log("Edges.length before: ", edges.length); const edgeRefs = operation.createEdge(group, [ [0, 0, 0], [0, 1, 1], [0, 1, 0], ]); edges = await group.entities.get({ filterBy: { types: ['Edge'] } }); console.log("Edges.length after: ", edges.length);}, 'Creating a Group and adding an Edge to that Group');Adding a Face to a Group
Section titled “Adding a Face to a Group”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const groupRef = operation.createGroup(model); operation.groupSetName(groupRef, 'A Group with a Face'); const group = await operation.entityForRef(groupRef); let faces = await group.entities.get({ filterBy: { types: ['Face'] } }); console.log("Faces.length before: ", faces.length); operation.createFace(groupRef, [ [0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0], ]); faces = await group.entities.get({ filterBy: { types: ['Face'] } }); console.log("Faces.length after: ", faces.length);}, 'Creating a Group and adding a Face to that Group');Get the Bounds(BoundingBox) of a Group
Section titled “Get the Bounds(BoundingBox) of a Group”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const groupRef = operation.createGroup(model); operation.groupSetName(groupRef, 'Some Group'); operation.createConstructionPoint(groupRef, [-100, 0, 0]); operation.createConstructionPoint(groupRef, [100, 100, 0]); const group = await operation.entityForRef(groupRef); const bounds = await group.getBounds(); console.log("Group's bounds: ", bounds.to_s);}, 'get groups bounds');Removing a Group
Section titled “Removing a Group”let model = await SketchUpApi.getActiveModel();await model.performOperation(operation => { const groupRef = operation.createGroup(model); operation.groupSetName(groupRef, 'A Group to be Removed'); return operation.drawingElementEraseWithForce(groupRef);}, 'removing group');