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) ⇒ Sketchup::Extension

Note:

It is recommended to omit the file extension provided in the path argument. SketchUp will resolve the file extension to .rbe, .rbs or .rb.

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')

# 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)

Parameters:

  • title (String)

    The name of the extension

  • path (String)

    The relative path to the script that loads your plugin.

Version:

  • SketchUp 6.0

Instance Method Details

#checkBoolean

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:

  • (String)

    the Extension copyright

Version:

  • SketchUp 6.0

#copyright=(copyright) ⇒ String

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

Parameters:

  • copyright (String)

    The copyright to set

Returns:

  • (String)

    the new copyright

Version:

  • SketchUp 6.0

#creatorString

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:

  • (String)

    the Extension creator

Version:

  • SketchUp 6.0

#creator=(creator) ⇒ String

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

Parameters:

  • creator (String)

    The creator to set

Returns:

  • (String)

    the new creator

Version:

  • SketchUp 6.0

#descriptionString

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:

  • (String)

    the Extension description

Version:

  • SketchUp 6.0

#description=(description) ⇒ String

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

Parameters:

  • description (String)

    The description string to set.

Returns:

  • (String)

    the Extension description

Version:

  • SketchUp 6.0

#extension_pathString

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

Returns:

  • (String)

    the file system path to the extension

Version:

  • SketchUp 2013

#idString

The id method returns the Extension Warehouse ID string.

Returns:

  • (String)

    the Extension Warehouse ID

Version:

  • SketchUp 2013

#load_on_start?Boolean

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)

Version:

  • SketchUp 8.0 M2

#loaded?Boolean

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)

Version:

  • SketchUp 8.0 M2

#nameString

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:

  • (String)

    the Extension name

Version:

  • SketchUp 6.0

#name=(name) ⇒ String

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'

Parameters:

  • name (String)

    The new name

Returns:

  • (String)

    the Extension name

Version:

  • SketchUp 6.0

#registered?Boolean

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)

Version:

  • SketchUp 8.0 M2

#uncheckBoolean

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

#versionString

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:

  • (String)

    the Extension version

Version:

  • SketchUp 6.0

#version=(version) ⇒ String

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

Parameters:

  • version (String)

    The version string to set.

Returns:

  • (String)

    the Extension version

Version:

  • SketchUp 6.0

#version_idString

The version_id method returns the Extension Warehouse Version ID string.

Returns:

  • (String)

    the Extension Warehouse Version ID string

Version:

  • SketchUp 2013