Tags
Creating a Tag
Section titled “Creating a Tag”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const tagRef = operation.createTag('Tag Name'); const tag = await operation.entityForRef(tagRef); console.log(tag.name);}, 'Create a Tag');Setting Tag Color and Visibility
Section titled “Setting Tag Color and Visibility”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const tagRef = operation.createTag('Tag Name'); operation.tagSetColor(tagRef, new SketchUpApi.Color(255, 10, 22, 255)); operation.tagSetVisible(tagRef, false);
const tag = await operation.entityForRef(tagRef); console.log("Color: ", tag.color.red, tag.color.green, tag.color.blue, tag.color.alpha); console.log("Visibility: ", tag.visible);}, 'Creating a Tag, setting color and visibility');Remove a Tag
Section titled “Remove a Tag”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const tagName = 'tagToRemove'; let tagManager = await model.getTagManager(); const tagRef = operation.createTag(tagName, tagManager); tagManager = await tagManager.refresh(); console.log("Tag should exist", tagManager.findTag(tagName)) operation.removeTag(tagRef); tagManager = await tagManager.refresh(); console.log("Tag should be removed", tagManager.findTag(tagName));}, 'Create and remove a Tag');let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const tagFolderRef = operation.createTagFolder('Tag Folder Name'); const tagFolder = await operation.entityForRef(tagFolderRef); console.log(tagFolder.name);}, 'Create a Tag Folder');Setting TagFolder Visibility
Section titled “Setting TagFolder Visibility”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const tagFolderRef = operation.createTagFolder('Tag Folder Name'); let tagFolder = await operation.entityForRef(tagFolderRef); console.log("Visibility before: ", tagFolder.visible); operation.tagFolderSetVisible(tagFolderRef,false); tagFolder = await tagFolder.refresh(); console.log("Visibility after: ", tagFolder.visible);}, 'Create a Tag Folder and setting visibility');Creating a TagFolder and a Tag inside a TagFolder
Section titled “Creating a TagFolder and a Tag inside a TagFolder”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const parentFolderRef = operation.createTagFolder('Parent Folder'); const childFolderRef = operation.createTagFolder('Child Folder', parentFolderRef); const childTagRef = operation.createTag('Child Tag', parentFolderRef); const parentFolder = await operation.entityForRef(parentFolderRef); const childFolder = await operation.entityForRef(childFolderRef); const childTag = await operation.entityForRef(childTagRef);
console.log("parentFolder.id: ", parentFolder.id); console.log("childTag.folderId: ", childTag.folderId); console.log("childFolder.folderId: ", childFolder.folderId);
}, 'Create a Tag Folder and a Tag inside a Tag Folder');let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const tagFolderName = 'tagFolderToRemove'; let tagManager = await model.getTagManager(); const tagFolderRef = operation.createTagFolder(tagFolderName, tagManager); tagManager = await tagManager.refresh(); console.log("TagFolder should Exist", tagManager.findTagFolder(tagFolderName))operation.removeTagFolder(tagFolderRef);tagManager = await tagManager.refresh();console.log("TagFolder should be removed", tagManager.findTagFolder(tagFolderName))}, 'Create and remove a TagFolder');