RBZs in SketchUp 8M2: Distribute Your Plugin as One File!
Posted by Scott Lininger, SketchUp Engineer
In the latest and greatest SketchUp 8 maintenance release, M2, we added an easier way for users to install your Ruby scripts. In the past, folks had to manually copy your .rb files into their Plugins folder, or you would have to write a custom installer to do it for them.
Now there’s a button in SketchUp that’ll make this easier. It’s found under Preferences > Extensions > Install Extension. Clicking this button will bring up a file browser window where your users can select any .RBZ file from their harddrive, and SketchUp will put them in the right spot plus load them up. No more fumbling around looking for the Plugins folder. No need to restart SketchUp to see your shiny plugin.
But what is an RBZ file?
And how do I make one?
It’s simple. RBZ files are nothing more than ZIP files. You can use your favorite ZIP tool (I like 7-zip on Windows) to create the archive, then rename it to have a .RBZ extension. Anything you put inside of this RBZ file, including files and subfolders, will be unpacked into the user’s Plugins folder. That’s it!
So let’s say you had a plugin with the following files in it:
- SketchUp 8/Plugins/helloworld.rb
- SketchUp 8/Plugins/helloworld_files/hello.html
- SketchUp 8/Plugins/helloworld_files/smiley.png
You would create a ZIP file containing the above files. With my ZIP tool, I simply select the helloworld.rb and helloworld_files folder, right click on them, and select “Create ZIP”. The resulting file is called helloworld.zip. Right click > rename to helloworld.rbz, and you’re golden. HOWEVER, before I do this, it would be even better to change my simple ruby script into a SketchupExtension. That way my users will see your Extension added to the Extensions panel when they do the install, and in the future it’s easy for them to turn it off.
Happy distributing!
Hidden Corners of SketchUp’s Ruby API: Transforming Vertices
Posted by Scott Lininger, SketchUp team
There are many capabilities of the SketchUp Ruby API that aren’t easy to discover. With over 1000 methods, it’s not surprising! In this semi-regular blog series, I’ll be pointing out my favorites.
Here’s one: tra…
Being a Good SketchUp Ruby Citizen
Posted by Scott Lininger, SketchUp TeamIn the world of Ruby scripts, keep in mind that users who will install your SketchUp plugin probably have installed other SketchUp plugins, too. Since Ruby is a wide-open language that lets you override and inspec…
Posted by Scott Lininger, SketchUp TeamAround the office here we’re always amazed at the awesome Ruby scripts you developers create. They make SketchUp more productive, smarter, and downright snazzy. So it’s no surprise when we hear from users who have…
The go_faster Parameter
Posted by Scott Lininger, SketchUp TeamSo I’ve been sitting in on a lot of product demos recently from some great Ruby API developers, and in a couple of cases they did not know about the “go_faster” parameter.The “go_faster” parameter, you say. What’s…
The SketchUp 7 SDK is now available
Posted by Bryce Stout, SketchUp TeamWe have recently updated the SketchUp SDK for folks who need read and/or write SketchUp 7 files. It is available on http://code.google.com/apis/sketchup/docs/downloadsdksubmit.html. If you have feedback or questio…
The SketchUp 7 SDK is now available
Posted by Bryce Stout, SketchUp TeamWe have recently updated the SketchUp SDK for folks who need read and/or write SketchUp 7 files. It is available on http://code.google.com/apis/sketchup/docs/downloadsdksubmit.html. If you have feedback or questio…
Playing Sounds in SketchUp
Posted by Scott Lininger, SketchUp Team
This week I’d like to talk about a much-maligned feature of the SketchUp Ruby API… UI.play_sound. Why would you ever want to play sound via the Ruby API? Glad you asked!
Besides the obvious desire to listen to Marvin Gaye while drawing your skatepark, you could enhance a scene tour with sound effects that match the location where your camera is located. It puts the multi in multimedia. Sounds fun, right? Let’s try it.
Step 1: Get a Zoo With some Scenes
For this exercise, we’re going to need a model with some Scene tabs. Luckily I have just the zoo. Click here to download a ZIP file with everything you need to follow this example.
Once you get it, unzip everything to your SketchUp/Plugins/ directory. It contains four files:
- zoo.skp – a model of the world’s lamest zoo
- zoo.rb – the code that we’re about to talk about
- zoo_lion.wav – what the lion says
- zoo_elephant.wav – what the elephant says
- zoo_sang.wav – what Sang says
Step 2: Don’t Feed the Animals
Once everything is in your /Plugins/ directory, open the zoo.skp file
and click the Scene tabs. Turn up the volume. You should hear a sound
effect that the Ruby API plays at each scene stop.
Step 3: Explore the Code
Here’s the entire script. It shows using a Page Observer to capture
each frame of our scene animations. It watches the callback parameter
percent_done to figure out when the animation is complete, and then
it plays the sound.
# Create a class that will "observe" frame changes.
class ZooFrameObserver
def frameChange(from_page, to_page, percent_done)
if percent_done == 1.0
if to_page == Sketchup.active_model.pages[0]
UI.play_sound("Plugins/zoo_lion.wav")
elsif to_page == Sketchup.active_model.pages[1]
UI.play_sound("Plugins/zoo_elephant.wav")
elsif to_page == Sketchup.active_model.pages[2]
UI.play_sound("Plugins/zoo_sang.wav")
end
end
end
end
# Attach our observer.
Sketchup::Pages.add_frame_change_observer(ZooFrameObserver.new)
I look forward to the day when every ruby script will play sounds with each interaction. I also like the blink tag. Huzzah!
Playing Sounds in SketchUp
Posted by Scott Lininger, SketchUp TeamThis week I’d like to talk about a much-maligned feature of the SketchUp Ruby API… UI.play_sound. Why would you ever want to play sound via the Ruby API? Glad you asked!Besides the obvious desire to listen to Ma…
Posted by Scott Lininger, SketchUp TeamSketchUp 7 contains several improvements to the Ruby API. Here’s a quick tour of the best changes.Improve your script’s performance!Ability to perform faster inside start_operation transactions.go_faster = truemod…
Posted by Scott Lininger, SketchUp Team
SketchUp 7 contains several improvements to the Ruby API. Here’s a quick tour of the best changes.
-
Improve your script’s performance!
Ability to perform faster inside start_operation transactions.
go_faster = true
model.start_operation operation_name, go_faster
Results from some real world tests, 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, 12×12
16.1 seconds vs. 7.0 seconds (~43% as as long)
Windowizer 4.0 with Ten 5′x5′ windows, 6×6
22.6 seconds vs 8.7 seconds (~38% as long)
-
Leverage improved Web Dialogs
Addition of min/max widths.
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)
-
Control Scale Tool handles on your components
Your script can now control which scale tool handles appear
# 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 2)
-
Load Definitions from the Web, or save to disk
Ability to download a definition from URL
model.definitions.load_from_url(url, download_handler)
Ability to Save components to disk from the API
my_definition.save_as(path)
-
Know more about what your users are doing
New methods for detecting “Component Edit” mode
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)
-
Delete your scenes via the API
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
-
and your users will benefit from numerous stability fixes!
Detailed documentation is coming soon… stay tuned!
Posted by Scott Lininger, SketchUp EngineerDrawing foodstuffs in SketchUp is fantastically cool, but at the end of the day you wind up with a meal that is, sigh, static. You can push your food about manually, of course, or you can hide or change its ap…
Posted by Scott Lininger, SketchUp Software EngineerYou’ve just SketchUped an amazing Robot Monkey, and you’re ready to include him in your company brochure. Excitedly, you email the 3D PDF over to the legal department for approval, and you’re faced wi…
Posted by Scott Lininger, SketchUp Software EngineerIf you are building rich WebDialogs in your SketchUp Plugin, then you are probably using Javascript + DHTML (Dynamic HTML) to show the UI and handle user input. In practical terms, this means that you…