Advanced Ruby Scripting For Sketch Up

4,884 views

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,884
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
68
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Advanced Ruby Scripting For Sketch Up

  1. 1. Advanced Ruby Scripting for SketchUp Scott Lininger May 29, 2008
  2. 2. What’s SketchUp? Google’s 3D drawing tool Used and loved by design professionals and hobbyists Easy to learn yet powerful Free and Pro versions are available On the Nerdy Side… Client application for PC & Mac Written in C++ and Objective C OpenGL for display layer Has a Ruby programming API
  3. 3. How Do I Get to the API? If you have SU, you have the API You write a Ruby Script Put your script into /SketchUp 6/Plugins folder and restart SU Control SketchUp via a powerful, consistent Object model Sketchup.active_model.camera.eye.x entities[0].transform! by_some_amount edge.faces[0].material = some_color
  4. 4. WebDialogs WebDialogs provide an embedded browser inside SketchUp Internet Explorer on PC Webkit/Safari on Mac
  5. 5. Ruby Extension Modules Extend Ruby with native code binary (aka extension module) Better performance Better IP protection of your code
  6. 6. 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 JS calls a ruby method and sends down that data to SketchUp as a string Stock Grabber Demo + Footprinter
  7. 7. 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? Secret Just don’t call .show() method Demo Stock Grabber
  8. 8. 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.
  9. 9. Advanced Technique 4: Animate using Javascript’s setTimeout Create a timer in Javascript… timerID = setTimeout(quot;nextFrame()quot;, 500) It runs in the browser’s thread (not SketchUp’s) Quietly sends commands to Ruby to create animation. Demo Spin My Yoda
  10. 10. 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
  11. 11. Advanced Technique 6: Bring ‘em all together JS + Ruby Games in SketchUp Prince IO Dem The SketchUp Knight o
  12. 12. 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
  13. 13. 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

×