14
Advanced Ruby Scripting for SketchUp Scott Lininger May 29, 2008

Advanced Ruby Scripting For Sketch Up

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Advanced Ruby Scripting For Sketch Up

Advanced Ruby Scripting for SketchUpScott LiningerMay 29, 2008

Page 2: Advanced Ruby Scripting For Sketch Up

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

Page 3: Advanced Ruby Scripting For Sketch Up

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

entities[0].transform! by_some_amount

edge.faces[0].material = some_color

Sketchup.active_model.camera.eye.x

Page 4: Advanced Ruby Scripting For Sketch Up

WebDialogs

WebDialogs provide an embedded browser inside SketchUp

Internet Explorer on PC

Webkit/Safari on Mac

Page 5: Advanced Ruby Scripting For Sketch Up

Ruby Extension Modules

Extend Ruby with native code binary (aka extension module)

Better performance

Better IP protection of your code

Page 6: Advanced Ruby Scripting For Sketch Up

Advanced Technique 1:

Ruby Opens a Webdialog to some webpage

The page uses AJAX or other techniques to pull dataTIP: 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

Grab and Render Web Data

Stock Grabber + FootprinterDemo

Page 7: Advanced Ruby Scripting For Sketch Up

Advanced Technique 2:

Hide the Web Dialog

SecretStock GrabberDemo

Provides a “permanent” Javascript environment

Javascript can take control at any time

How to do it on the PC?

On the Mac?Just don’t call .show() method

my_dialog.show()my_dialog.set_position(9999,9999)

Page 8: Advanced Ruby Scripting For Sketch Up

Advanced Technique 3:

Move the camera to control user experience

Export 2D screenshots to get web-friendly output from SU

http://sketchup.google.com/download/plugins.html3D Exporter is an open source project! Please contribute.

Use WebDialogs + Ruby to Control the Camera

3D ExporterDemo

Page 9: Advanced Ruby Scripting For Sketch Up

Advanced Technique 4:

Create a timer in Javascript…

It runs in the browser’s thread (not SketchUp’s)

Quietly sends commands to Ruby to create animation.

Animate using Javascript’s setTimeout

Spin My YodaDemo

timerID = setTimeout("nextFrame()", 500)

Page 10: Advanced Ruby Scripting For Sketch Up

Advanced Technique 5:

document.onClick can capture keystrokes

dialog.show_modal() can force focus to your dialog

Interesting way of adding keyboard support to SketchUp

Capture Key Strokes with Javascript

Nudge My YodaDemo

Page 11: Advanced Ruby Scripting For Sketch Up

Advanced Technique 6:

JS + Ruby Games in SketchUp

Bring ‘em all together

Prince IOThe SketchUp KnightDem

o

Page 12: Advanced Ruby Scripting For Sketch Up

Advanced Technique 7:

Take these animation and processing techniques to the next level

SketchyPhysics is a great example… numerous demos on YouTube

Ruby Extension Modules

Page 13: Advanced Ruby Scripting For Sketch Up

Learn More

Get SketchUphttp://sketchup.google.com

API Documentationhttp://code.google.com/apis/sketchup/

Join the SketchUp API Bloghttp://sketchupapi.blogspot.com/

Join the Ruby User Grouphttp://groups.google.com/group/Ruby-API

Page 14: Advanced Ruby Scripting For Sketch Up