Class: Sketchup::Styles

Inherits:
Entity
  • Object
show all
Includes:
Enumerable

Overview

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

Examples:

styles = Sketchup.active_model.styles
UI.messagebox "There are " + styles.count.to_s + " styles in your model."

Version:

  • SketchUp 6.0

Instance Method Summary collapse

Methods inherited from Entity

#add_observer, #attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #inspect, #model, #persistent_id, #remove_observer, #set_attribute, #to_s, #typename, #valid?

Instance Method Details

#[](name_or_index) ⇒ Object

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

Examples:

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

Returns style - a Style object if successful

Parameters:

  • name_or_index

    The string name or index for a specific style.

Returns:

  • style - a Style object if successful

Version:

  • SketchUp 6.0

#active_styleObject

The active_style method is used to retrieve the active style.

Examples:

styles = Sketchup.active_model.styles
style = styles.active_style
UI.messagebox('The active style is: ' + active_style.name)

Returns:

  • style - the active Style object.

Version:

  • SketchUp 6.0

#active_style_changedObject

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
user_made_change = styles.active_style_changed
UI.messagebox ('The active style was edited: ' + user_made_change.to_s)

Returns:

  • changed - true if the active style has been changed from when it was last saved.

Version:

  • SketchUp 6.0

#add_style(filename, select) ⇒ Object

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

Examples:

styles = Sketchup.active_model.styles
status = styles.add_style "c:\\MyStyle.style", true
UI.messagebox ('A style was added: ' + status.to_s)

Returns status - true if successful, false if unsuccessful.

Parameters:

  • filename

    The filename for the style.

  • select

    true if you want to set the style to be the active style, false if not.

Returns:

  • status - true if successful, false if unsuccessful.

Version:

  • SketchUp 6.0

#countObject

Note:

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

Returns integer - the number of styles found.

Examples:

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

Returns:

  • integer - the number of styles found.

Version:

  • SketchUp 6.0

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

The each method is used to iterate through styles.

Examples:

styles = Sketchup.active_model.styles
styles.each {| style |
  UI.messagebox('style: ' + style.name)
}

Yields:

  • (style)

    Variable that will hold each style as it is found.

Returns:

  • nil

Version:

  • SketchUp 6.0

#lengthObject

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

The #length method is an alias of #size.

Examples:

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

Returns:

  • integer - the number of styles found.

Version:

  • SketchUp 6.0

#parentObject

parent pointer, so we can't use the normal “parent” method from Entity

#purge_unusedObject

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

Examples:

styles = Sketchup.active_model.styles
status = styles.purge_unused
UI.messagebox ('Purging Unused styles status: ' + status.to_s)

Returns:

  • status - true if successful, false if unsuccessful.

Version:

  • SketchUp 6.0

#selected_styleObject

The selected_style method is used to retrieve the currently selected style.

Examples:

styles = Sketchup.active_model.styles
style = styles.selected_style
UI.messagebox ('The selected style is: ' + style.name)

Returns:

  • style - the selected Style object.

Version:

  • SketchUp 6.0

#selected_style(style) ⇒ Object

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

Examples:

styles = Sketchup.active_model.styles
styles.selected_style = styles[styles.count -1]

Returns false

Parameters:

  • style

    The style object to select.

Returns:

  • false

Version:

  • SketchUp 6.0

#sizeObject

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

The #length method is an alias of #size.

Examples:

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

Returns:

  • integer - the number of styles found.

Version:

  • SketchUp 6.0

#update_selected_styleObject

The update_selected_style method returns true if the selected style was changed (e.g. the user selected a different style).

Examples:

styles = Sketchup.active_model.styles
success = styles.update_selected_style
UI.messagebox ('The selected style was switched: ' + success.to_s)

Returns:

  • status - true if the style was switched

Version:

  • SketchUp 6.0