Advanced Ruby Scripting For SketchUp
Advanced Ruby Scripting For SketchUp
Advanced Ruby Scripting For SketchUp
for SketchUp
Scott Lininger
May 29, 2008
Whats SketchUp?
Googles 3D drawing tool
Used and loved by design professionals and hobbyists
Easy to learn yet powerful
Free and Pro versions are available
entities[0].transform! by_some_amount
edge.faces[0].material = some_color
WebDialogs
WebDialogs provide an embedded browser inside
SketchUp
Internet Explorer on PC
Webkit/Safari on Mac
Advanced Technique 1:
Grab and Render Web Data
Ruby Opens a Webdialog to some webpage
The page uses AJAX or other techniques to pull data
TIP: If your webpage is local, you can get data across
domains
Demo
Stock Grabber
+ Footprinter
Advanced Technique 2:
Hide the Web Dialog
Provides a permanent Javascript environment
Javascript can take control at any time
How to do it on the PC?
my_dialog.show()
my_dialog.set_position(9999,9999)
On the Mac?
Just dont call .show() method
Demo
Secret
Stock Grabber
Advanced Technique 3:
Use WebDialogs + Ruby to Control the Camera
Move the camera to control user experience
Export 2D screenshots to get web-friendly output from SU
Demo
3D Exporter
http://sketchup.google.com/download/plugins.html
3D Exporter is an open source project! Please contribute.
Advanced Technique 4:
Animate using Javascripts setTimeout
Create a timer in Javascript
timerID = setTimeout("nextFrame()", 500)
Demo
Spin My Yoda
Advanced Technique 5:
Capture Key Strokes with Javascript
document.onClick can capture keystrokes
dialog.show_modal() can force focus to your dialog
Interesting way of adding keyboard support to SketchUp
Demo
Nudge My Yoda
Advanced Technique 6:
Bring em all together
JS + Ruby Games in SketchUp
Dem
o
Prince IO
The SketchUp Knight
Advanced Technique 7:
Ruby Extension Modules
Take these animation and processing techniques to
the next level
SketchyPhysics is a great example numerous demos on
YouTube
Learn More
Get SketchUp
http://sketchup.google.com
API Documentation
http://code.google.com/apis/sketchup/
Join the SketchUp API Blog
http://sketchupapi.blogspot.com/
Join the Ruby User Group
http://groups.google.com/group/Ruby-API