14180166 advanced ruby scripting for sketchup

Upload: nishant-prakhar

Post on 03-Apr-2018

247 views

Category:

Documents


23 download

TRANSCRIPT

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    1/14

    Advanced Ruby Scriptingfor SketchUpScott LiningerMay 29, 2008

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    2/14

    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

    On the Nerdy Side

    Client application for PC & Mac

    Written in C++ and Objective C

    OpenGL for display layer

    Has a Ruby programming API

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    3/14

    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 restartSU

    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

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    4/14

    WebDialogs

    WebDialogs provide an embedded browser insideSketchUp

    Internet Explorer on PC

    Webkit/Safari on Mac

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    5/14

    Ruby Extension Modules

    Extend Ruby with native code binary (aka extensionmodule)

    Better performance

    Better IP protection of your code

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    6/14

    Advanced Technique 1:

    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 toSketchUp as a string

    Grab and Render Web Data

    Stock Grabber+ Footprinter

    Demo

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    7/14

    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 dont call .show() method

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

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    8/14

    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.html

    3D Exporter is an open source project! Please contribute.

    Use WebDialogs + Ruby to Control the Camera

    3D ExporterDemo

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    9/14

    Advanced Technique 4:

    Create a timer in Javascript

    It runs in the browsers thread (not SketchUps)

    Quietly sends commands to Ruby to create animation.

    Animate using Javascripts setTimeout

    Spin My YodaDemo

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

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    10/14

    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

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    11/14

    Advanced Technique 6:

    JS + Ruby Games in SketchUp

    Bring em all together

    Prince IOThe SketchUp KnightDem

    o

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    12/14

    Advanced Technique 7:

    Take these animation and processing techniques tothe next level

    SketchyPhysics is a great example numerous demos onYouTube

    Ruby Extension Modules

    http://uk.youtube.com/watch?v=qLvXvzPvfWI&feature=related
  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    13/14

    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

  • 7/28/2019 14180166 Advanced Ruby Scripting for SketchUp

    14/14