Class: SketchupExtension

Inherits:
Object
  • Object
show all

Overview

The SketchupExtension class contains methods allowing you to create and manipulate SketchUp extensions. Extensions are Ruby scripts that can be loaded and unloaded using the Extension manager (Extensions panel of the Preferences dialog box). Generally you should register your ruby scripts as an extension to give SketchUp users the ability to disable it through the user interface.

The idea here is to take the ruby script that actually creates your functionality and place it in a folder somewhere outside of the /Plugins folder, most commonly a subdirectory like /Plugins/MyExtension. Then you create a new ruby script inside the /Plugins directory that will set up the extension entry and load your original script if the user has your extension turned on.

Here is an example extension loading script. For this example, the following code would be saved in /Plugins/StairTools.rb, and the actual plugin itself would live in /Plugins/StairTools/core.rb.

You can find two example extensions that ship with SketchUp, su_dynamiccomponents.rb and su_sandboxtools.rb, under the /Plugins/ folder.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
require 'sketchup.rb'
require 'extensions.rb'

stair_extension = SketchupExtension.new('Stair Tools", "StairTools/core.rb')
stair_extension.version = '1.0'
stair_extension.description = 'Tools to draw stairs automatically.'
Sketchup.register_extension(stair_extension, true)

Version:

  • SketchUp 6.0

Instance Method Summary # collapse

Constructor Details

#initialize(title, path) ⇒ Object

The new method is used to create a new SketchupExtension object. Note that once the extension object is created, it will not appear in the Extension Manager dialog until your register it with the Sketchup.register_extension method.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')

# Then be sure to register it. By passing a 2nd param of true, you're
# telling SketchUp to load the extension by default.
Sketchup.register_extension(extension, true)

Returns extension - the new Extension object

Parameters:

  • title

    The name of the extension

  • path

    The relative path to the script that loads your plugin.

Version:

  • SketchUp 6.0

Instance Method Details

#checkObject

Loads the extension, meaning the underlying ruby script is immediately interpreted. This is the equivalent of checking the extension's checkbox in the Preferences > Extensions list.

Examples:

# This will register the extension, a necessary step for it to appear
# in SketchUp's Preferences > Extensions list
ext_c = SketchupExtension.new('Stair Tools C', 'StairTools/core.rb')
Sketchup.register_extension(ext_c, false)

# And this will load the extension.
ext_c.check

Returns:

  • boolean - whether the load succeeded

Version:

  • SketchUp 8.0 M2

The copyright method returns the copyright string which appears beneath an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.copyright = '2008'
copyright = extension.copyright

Returns:

  • copyright - the Extension copyright

Version:

  • SketchUp 6.0

#copyright=(copyright) ⇒ Object

The copyright= method sets the copyright string which appears beneath an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.copyright = '2008'
copyright = extension.copyright

Returns copyright - the new copyright

Parameters:

  • copyright

    The copyright to set

Returns:

  • copyright - the new copyright

Version:

  • SketchUp 6.0

#creatorObject

The creator method returns the creator string which appears beneath an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.creator = 'Trimble Navigation, Inc.'
creator = extension.creator

Returns:

  • creator - the Extension creator

Version:

  • SketchUp 6.0

#creator=(creator) ⇒ Object

The creator= method sets the creator string which appears beneath an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.creator = 'Trimble Navigation, Inc.'
creator = extension.creator

Returns creator - the new creator

Parameters:

  • creator

    The creator to set

Returns:

  • creator - the new creator

Version:

  • SketchUp 6.0

#descriptionObject

The description method returns the long description which appears beneath an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.description = 'My description.'
description = extension.description

Returns:

  • description - the Extension description

Version:

  • SketchUp 6.0

#description(description) ⇒ Object

The description= method sets the long description which appears beneath an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.description = 'My description.'
description = extension.description

Returns description - the Extension description

Parameters:

  • description

    The description string to set.

Returns:

  • description - the Extension description

Version:

  • SketchUp 6.0

#extension_pathObject

The extension_path method returns the file system path to the extension's outer rb file.

Returns:

  • extension_path - the file system path to the extension

Version:

  • SketchUp 2013

#idObject

The id method returns the Extension Warehouse ID string.

Returns:

  • id - the Extension Warehouse ID

Version:

  • SketchUp 2013

#load_on_start?Object

Returns whether the extension is set to load when SketchUp starts up.

Examples:

ext = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
UI.messagebox("load_on_start? is false: #{ext.load_on_start?.to_s}")
Sketchup.register_extension(ext, true)
UI.messagebox("load_on_start? is now true: #{ext.load_on_start?.to_s}")

Returns:

  • boolean - true if the extension loads on startup.

  • (Boolean)

Version:

  • SketchUp 8.0 M2

#loaded?Object

Returns whether the extension is currently loaded, meaning the actual ruby script that implements the extension has been evaluated.

Examples:

ext = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
UI.messagebox("loaded? is false: #{ext.loaded?.to_s}")
Sketchup.register_extension ext, true
UI.messagebox("loaded? is now true: #{ext.loaded?.to_s}")

Returns:

  • boolean - true if the extension has been loaded

  • (Boolean)

Version:

  • SketchUp 8.0 M2

#nameObject

The name method returns the name which appears for an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
name = extension.name

Returns:

  • name - the Extension name

Version:

  • SketchUp 6.0

#name=(name) ⇒ Object

The name= method sets the name which appears for an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.name = 'Renamed Stair Tools'

Returns name - the Extension name

Parameters:

  • name

    The new name

Returns:

  • name - the Extension name

Version:

  • SketchUp 6.0

#registered?Object

Returns whether the extension has been registered via Sketchup.register_extension.

Examples:

ext = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
UI.messagebox("My registered? is false: #{ext.registered?.to_s}")
Sketchup.register_extension(ext, true)
UI.messagebox("Now registered? is now true: #{ext.registered?.to_s}")

Returns:

  • boolean - true if the extension has been registered.

  • (Boolean)

Version:

  • SketchUp 8.0 M2

#uncheckObject

Unloads the extension. This is the equivalent of unchecking the extension's checkbox in the Preferences > Extensions list.

Note that technically the extension is not “unloaded” in the sense that it stops running during the current SketchUp session, but the next time the user restarts SketchUp, the extension will not be active.

Examples:

# This unloads all extensions. The next time SketchUp starts, none of
# the extensions will be active.
Sketchup.extensions.each { |extension|
  extension.uncheck
}

Returns:

  • boolean - whether the unload succeeded

Version:

  • SketchUp 8.0 M2

#versionObject

The version method returns the version which appears beneath an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.version = '5.0'
version = extension.version

Returns:

  • version - the Extension version

Version:

  • SketchUp 6.0

#version=(version) ⇒ Object

The version method sets the version which appears beneath an extension inside the Extensions Manager dialog.

Examples:

# Create an entry in the Extension list that loads a script called
# core.rb.
extension = SketchupExtension.new('Stair Tools', 'StairTools/core.rb')
extension.version = '5.0'
version = extension.version

Returns version - the Extension version

Parameters:

  • version

    The version string to set.

Returns:

  • version - the Extension version

Version:

  • SketchUp 6.0

#version_idObject

The version_id method returns the Extension Warehouse Version ID string.

Returns:

  • version_id - the Extension Warehouse Version ID string

Version:

  • SketchUp 2013