The SketchUp API has been around in some fashion since the early days of SketchUp, and with every release we have extended its capabilities. Read below for what's been changed.
Though our adoption rate to the latest version is quite high, it can take time after a release before everyone upgrades. If you are building scripts that rely on functionality from the most recent version, be sure to check the Sketchup.version to make sure your users are able to run your script:
# You can have this sort of code in the initialization routine of your plugin. version_required = 7.0 if (Sketchup.version.to_f < version_required) UI.messagebox("You must have Sketchup " + version_required.to_s + " to run this plugin. Visit sketchup.google.com to upgrade.") return end
Find out how many faces are in your model.
model.number_faces
See if a model has been georeferenced for use in Earth.
model.georeferenced?
Force refresh of a view. More powerful that view.invalidate because it refreshes immediately.
view.refresh
Take a screen grab from any WebDialog.
mywebdialog.write_image 'img.jpg'
See what component instances are glued to a given face.
for (instance in myface.get_glued_instances) { ... }
What's new in SketchUp 7
operation_name = "My Processing" go_faster = true model.start_operation operation_name, go_faster # Do processing here that was slow in SU6 # ... model.start_operation commit_operation
Results from some real world tests, (comparing SU6 to SU7 on the same machine) once the go_faster boolean was added:
Intersect overlaps with 500 overlapping squares
28.4
seconds vs. 26.3 (~92% as long)
Make
faces with 500 faceless cubes
21.7 seconds vs. 14.5 (~66% as long)
Windowizer
3.0 with Four 20'x20' windows, 12x12
16.1 seconds vs. 7.0 seconds (~43%
as as long)
Windowizer
4.0 with Ten 5'x5' windows, 6x6
22.6 seconds vs 8.7 seconds (~38% as
long)
WebDialog.min_width=100 WebDialog.max_width=300 WebDialog.min_height=500 WebDialog.max_height=600
Fixed Mac support for WebDialogs execute_script
WebDialog.execute_script('alert("Bug is Fixed!")');
New full_security mode for webdialogs (disables plugins and remote links)
WebDialog.set_full_security
Ability to hide home/next/back navigation icons on the Mac
WebDialog.navigation_buttons_enabled=true
Cleaner, hash-based syntax for initializing
my_dialog = WebDialog.new(my_settings_hash)
# Disable the green and red-axes handles # by setting bits 1 and 2 to 1. behavior = my_component_definition.behavior behavior.no_scale_mask = (1 << 1) + (1 << 2)
model.definitions.load_from_url(url, download_handler)
Ability to Save components to disk from the API
my_definition.save_as(path)
users_current_edit = model.active_path edit_mode_transform = model.edit_transform
Easily determine if they're running in licensed Pro
is_licensed_pro = Sketchup.is_pro?
New "model level" callbacks in ModelObserver
def onActivePathChanged(model) { # Detect edit mode }
def onPlaceComponent(instance) { # Detect placements } def onExplode(model) { # Detect group/component explode } def onBeforeComponentSaveAs(instance) { # Add data on save as } def onAfterComponentSaveAs(instance) { # Then clean up }
Detect if they've turned off your extension via the AppObserver
def onUnloadExtension(extension_name)
my_page.erase
Keep SketchUp in Synch
UI.refresh_inspectors # force complete UI update my_definition.refresh_thumbnail # force thumb update my_definition.invalidate_bounds # force bb update
Measure your groups regardless of their transform
untransformed_bb = my_group.local_bounds
Use middle mouse button in your custom tools
def onMButtonDown(flags, x, y, view) { # now works! } def onMButtonUp(flags, x, y, view) { # now works! }
Send ruby console output to the standard out If you start up SketchUp from the command line, you can pipe to standard error and see ruby puts statements appear for you.
Sketchup.exe > myRubyLog.txt
Finally, we fixed a number of crashing bugs, mostly related to iterating across entities in the model.
The most substantial addition to the SketchUp 6 Ruby API are the Ruby Observer Mechanism, the Tools class, the WebDialog class, the Styles class, and the Style class.
Create a Ruby class of a specific observer type, such as AppObserver, override the desired methods, such as onQuit, and add an instance of the observer to the applicable objects in your Ruby script (using the add_observer method for that object). Refer to individual observer interfaces for further information.
The core 62 classes of the API were established here. Very few users are on anything before SketchUp 6, so this documentation site focuses only on SketchUp 6 and up.