123456789_123456789_123456789_123456789_123456789_

Class: Sketchup::Styles

Relationships
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Entity
Instance Chain:
self, Enumerable, Entity
Inherits: Sketchup::Entity

Overview

The Styles class contains methods for manipulating a collection of styles in a model. Typically, you will access this via the active_model:

There are two objects of this class that play important roles: the #selected_style and the #active_style.

The latter is a temporary copy made from the #selected_style that allows the user to edit the style without committing to save anything. To save the changes, one should use #update_selected_style.

Examples:

styles = Sketchup.active_model.styles
puts "There are #{styles.size} styles in your model."

Version:

  • SketchUp 6.0

Instance Attribute Summary

Entity - Inherited

#deleted?

The deleted? method is used to determine if your entity is still valid (not deleted by another script, for example.).

#valid?

The #valid? method is used to determine if your entity is still valid (not deleted by another script, for example).

Instance Method Summary

Entity - Inherited

#add_observer

The add_observer method is used to add an observer to the current object.

#attribute_dictionaries

The attribute_dictionaries method is used to retrieve the AttributeDictionaries collection attached to the entity.

#attribute_dictionary

The attribute_dictionary method is used to retrieve an attribute dictionary with a given name that is attached to an Entity.

#delete_attribute

The #delete_attribute method is used to delete an attribute from an entity.

#entityID

The entityID method is used to retrieve a unique ID assigned to an entity.

#get_attribute

The #get_attribute method is used to retrieve the value of an attribute in the entity’s attribute dictionary.

#inspect

The #inspect method is used to retrieve the string representation of the entity.

#model

The model method is used to retrieve the model for the entity.

#parent

The parent method is used to retrieve the parent of the entity.

#persistent_id

The #persistent_id method is used to retrieve a unique persistent id assigned to an entity.

#remove_observer

The remove_observer method is used to remove an observer from the current object.

#set_attribute

The set attribute is used to set the value of an attribute in an attribute dictionary with the given name.

#to_s

The #to_s method is used to retrieve the string representation of the entity.

#typename

The typename method retrieves the type of the entity, which will be a string such as “Face”, “Edge”, or “Group”.

Instance Attribute Details

#selected_styleSketchup::Style (rw)

The #selected_style method is used to retrieve the style currently selected in the Styles Browser.

Examples:

styles = Sketchup.active_model.styles
style = styles.selected_style

Returns:

Version:

  • SketchUp 6.0

#selected_style=(style) ⇒ nil (rw)

The #selected_style= method is used to set the currently selected style.

Examples:

styles = Sketchup.active_model.styles
filename = File.expand_path('./MyStyle.style')
styles.add_style(filename, true)
styles.selected_style = styles['[MyStyle]']

Parameters:

Raises:

Version:

  • SketchUp 6.0

Instance Method Details

#[](name) ⇒ Sketchup::Style? #[](index) ⇒ Sketchup::Style?

The #[] method is used to retrieves a style by either name or index.

Examples:

styles = Sketchup.active_model.styles
style1 = styles[0]
style2 = styles["MyStyle"]

Overloads:

  • #[](name) ⇒ Sketchup::Style?

    Parameters:

    • name (String)

      The name of the style to retrieve.

  • #[](index) ⇒ Sketchup::Style?

    Parameters:

    • index (Integer)

      The index of the style to retrieve.

Version:

  • SketchUp 6.0

#active_styleSketchup::Style

The #active_style method is used to retrieve the active style.

While #selected_style is the style being selected in the Style Browser, the #active_style is a different object also including any unsaved style changes. These changes are silently dropped once a new style is selected. To save these changes to the selected style, call ##update_selected_style.

Examples:

styles = Sketchup.active_model.styles
style = styles.active_style

Version:

  • SketchUp 6.0

#active_style_changedBoolean

The #active_style_changed method tells you if the active style has been edited by the user since it was last saved.

Examples:

styles = Sketchup.active_model.styles
style_changed = styles.active_style_changed

Version:

  • SketchUp 6.0

#add_style(filename, select) ⇒ Boolean #add_style(filename, select = false) ⇒ Boolean

The #add_style method is used to create and load a style from the given file.

Examples:

For SketchUp 2025.0 and older

filename = File.expand_path('./MyStyle.style')
styles = Sketchup.active_model.styles
status = styles.add_style(filename, true)

For SketchUp 2026.0 and newer

filename = File.expand_path('./MyStyle.style')
styles = Sketchup.active_model.styles
style = styles.add_style(filename, true)

Overloads:

  • #add_style(filename, select) ⇒ Boolean
    Note:

    Signature for versions prior to SketchUp 2026.0.

    Parameters:

    • filename (String)

      The file path to the style file.

    • select (Boolean)

      true if you want to set the style to be the active style.

    Version:

    • SketchUp 6.0

  • #add_style(filename, select = false) ⇒ Boolean

    Parameters:

    • filename (String)

      The file path to the style file.

    • select (Boolean) (defaults to: false)

      true if you want to set the style to be the active style.

    Version:

    • SketchUp 2026.0

Returns:

  • (Sketchup::Style, nil)

    The newly created style or nil if the the style could not be added.

#countInteger

Note:

Since SketchUp 2014 the count method is inherited from Ruby’s Enumerable mix-in module. Prior to that the #count method is an alias for #length.

Examples:

styles = Sketchup.active_model.styles
number = styles.count

Version:

  • SketchUp 6.0

#each {|style| ... } ⇒ nil

The #each method is used to iterate through styles.

Examples:

styles = Sketchup.active_model.styles
styles.each { |style|
  puts style.name
}

Yield Parameters:

Version:

  • SketchUp 6.0

#lengthInteger

The #length method is an alias of #size.

Examples:

styles = Sketchup.active_model.styles
number = styles.length

See Also:

Version:

  • SketchUp 2014

#parentSketchup::Model

The #parent method is used to return the model for the styles.

Examples:

styles = Sketchup.active_model.styles
model = styles.parent

Version:

  • SketchUp 6.0

#purge_unusednil

The #purge_unused method is used to remove unused styles from the model.

Examples:

styles = Sketchup.active_model.styles
styles.purge_unused

Version:

  • SketchUp 6.0

#remove_style(style) ⇒ nil

The #remove_style method is used to remove a Style from the Styles.

Examples:

filename = File.expand_path('./MyStyle.style')
styles = Sketchup.active_model.styles
status = styles.add_style(filename, true)
styles.remove(styles.first)

Parameters:

Raises:

  • (ArgumentError)

    If the style is not found in the Styles collection.

  • (ArgumentError)

    If the styles contains only one style.

Version:

  • SketchUp 2026.0

#sizeInteger

The #size method is used to retrieve the number of styles in the collection.

Examples:

styles = Sketchup.active_model.styles
number = styles.size

See Also:

Version:

  • SketchUp 6.0

#update_selected_stylenil

The #update_selected_style method commits the current style settings to the style selected in the Style Browser.

Examples:

styles = Sketchup.active_model.styles
styles.update_selected_style

See Also:

Version:

  • SketchUp 6.0