Skip to content

Style

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');
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');
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}`);
});
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);
let model = await SketchUpApi.getActiveModel();
let styles = await model.getStyles();
await model.performOperation(async operation => {
operation.setSelectedStyle(styles[0]);
}, 'Set selected style');
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');
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');
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');
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);
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');
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');
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');
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');
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');