Class: SketchupExtension

Inherits:
Object
  • Object
show all
Defined in:
lib/sketchup-api-stubs/stubs/sketchupextension.rb

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



210
211
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 210

def initialize(title, path)
end

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



57
58
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 57

def check
end

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



73
74
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 73

def copyright
end

#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



92
93
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 92

def copyright=(copyright)
end

#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



108
109
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 108

def creator
end

#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



127
128
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 127

def creator=(creator)
end

#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



143
144
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 143

def description
end

#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



162
163
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 162

def description=(description)
end

#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



171
172
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 171

def extension_path
end

#idString

The id method returns the Extension Warehouse ID string.

Returns:

  • (String)

    the Extension Warehouse ID

Version:

  • SketchUp 2013



179
180
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 179

def id
end

#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



224
225
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 224

def load_on_start?
end

#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



239
240
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 239

def loaded?
end

#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



254
255
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 254

def name
end

#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



272
273
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 272

def name=(name)
end

#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



287
288
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 287

def registered?
end

#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



307
308
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 307

def uncheck
end

#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



323
324
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 323

def version
end

#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



342
343
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 342

def version=(version)
end

#version_idString

The version_id method returns the Extension Warehouse Version ID string.

Returns:

  • (String)

    the Extension Warehouse Version ID string

Version:

  • SketchUp 2013



350
351
# File 'lib/sketchup-api-stubs/stubs/sketchupextension.rb', line 350

def version_id
end