Style
Loading a Style from a URL
Section titled “Loading a Style from a URL”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const styleRef = await operation.loadStyle({ resource: { request: 'https://cdn.habitat.sketchup.com/styles/defaults/Wireframe.style' }, deduplicate: true }); const style = await operation.entityForRef(styleRef); console.log('Loaded style:', style.name);}, 'Load style from URL');Loading a Style from a local file path
Section titled “Loading a Style from a local file path”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const styleRef = await operation.loadStyle({ resource: { request: '/path/to/local/style.style' }, deduplicate: false }); const style = await operation.entityForRef(styleRef); console.log('Loaded style:', style.name, style.description);}, 'Load style from file');Getting all Styles in the model
Section titled “Getting all Styles in the model”let model = await SketchUpApi.getActiveModel();let styles = await model.getStyles();console.log('Total styles:', styles.length);styles.forEach(style => { console.log(`Style: ${style.name} - ${style.description}`);});Getting the selected Style
Section titled “Getting the selected Style”let model = await SketchUpApi.getActiveModel();let selectedStyle = await model.getSelectedStyle();console.log('Selected style:', selectedStyle.style.name);console.log('Has been modified:', selectedStyle.info.hasBeenModified);console.log('File name:', selectedStyle.info.fileName);Setting the selected Style
Section titled “Setting the selected Style”let model = await SketchUpApi.getActiveModel();let styles = await model.getStyles();await model.performOperation(async operation => { operation.setSelectedStyle(styles[0]);}, 'Set selected style');Updating the selected Style with current rendering options
Section titled “Updating the selected Style with current rendering options”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { // Modify rendering options first await model.updateRenderingOptions({ EdgeDisplayMode: SketchUpApi.EdgeDisplayMode.All, DrawHidden: false }); // Update the selected style to capture these changes operation.updateSelectedStyle();}, 'Update selected style');Setting name for a Style
Section titled “Setting name for a Style”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const styles = await model.getStyles(); let style = styles[0]; console.log('Before name:', style.name); operation.styleSetName(style, 'My Custom Style'); style = await style.refresh(); console.log('After name:', style.name);}, 'Set style name');Setting description for a Style
Section titled “Setting description for a Style”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const styles = await model.getStyles(); let style = styles[0]; console.log('Before description:', style.description); operation.styleSetDescription(style, 'A custom style for my project'); style = await style.refresh(); console.log('After description:', style.description);}, 'Set style description');Getting rendering options for a Style
Section titled “Getting rendering options for a Style”let model = await SketchUpApi.getActiveModel();let styles = await model.getStyles();let renderingOptions = await styles[0].getRenderingOptions();console.log('Edge display mode:', renderingOptions.EdgeDisplayMode);console.log('Draw hidden:', renderingOptions.DrawHidden);console.log('Render mode:', renderingOptions.RenderMode);Updating rendering options for a Style
Section titled “Updating rendering options for a Style”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const styles = await model.getStyles(); operation.styleUpdateRenderingOptions(styles[0], { EdgeDisplayMode: SketchUpApi.EdgeDisplayMode.Standalone, DrawHidden: true, RenderMode: SketchUpApi.RenderMode.Hidden }); const updatedStyle = await styles[0].refresh(); const renderingOptions = await updatedStyle.getRenderingOptions(); console.log('Updated edge display mode:', renderingOptions.EdgeDisplayMode);}, 'Update style rendering options');Duplicating a Style
Section titled “Duplicating a Style”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const styles = await model.getStyles(); const originalStyle = styles[0]; console.log('Original style:', originalStyle.name);
const duplicateRef = operation.createDuplicateStyle(originalStyle); const duplicateStyle = await operation.entityForRef(duplicateRef); console.log('Duplicate style:', duplicateStyle.name);}, 'Duplicate style');Removing a Style
Section titled “Removing a Style”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const styles = await model.getStyles(); const styleToRemove = styles.find(s => s.name === 'Unwanted Style'); if (styleToRemove) { operation.removeStyle(styleToRemove); console.log('Removed style:', styleToRemove.name); }}, 'Remove style');Purging unused Styles
Section titled “Purging unused Styles”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { const beforeCount = (await model.getStyles()).length; console.log('Styles before purge:', beforeCount);
operation.purgeUnusedStyles();
// Refresh to get updated count const afterCount = (await model.getStyles()).length; console.log('Styles after purge:', afterCount); console.log('Purged:', beforeCount - afterCount, 'unused styles');}, 'Purge unused styles');Complete workflow: Load, customize, and apply a Style
Section titled “Complete workflow: Load, customize, and apply a Style”let model = await SketchUpApi.getActiveModel();await model.performOperation(async operation => { // Load a style from URL const styleRef = await operation.loadStyle({ resource: { request: 'https://cdn.habitat.sketchup.com/styles/defaults/Wireframe.style' }, deduplicate: true });
let style = await operation.entityForRef(styleRef); console.log('Loaded style:', style.name);
// Customize the style's name and description operation.styleSetName(style, 'My Custom Wireframe'); operation.styleSetDescription(style, 'Customized wireframe style for technical drawings');
// Update rendering options for the style operation.styleUpdateRenderingOptions(style, { EdgeDisplayMode: SketchUpApi.EdgeDisplayMode.Standalone, DrawHidden: false, RenderMode: SketchUpApi.RenderMode.Wireframe, DrawLineEnds: true });
// Apply the style to the model operation.setSelectedStyle(style);
style = await style.refresh(); console.log('Applied and customized style:', style.name);}, 'Load, customize and apply style');