The Ruby Console

The Ruby console is similar in functionality to Ruby's Interactive Ruby (irb) allowing you to experiment with Ruby commands and methods. This is a valuable tool for exploring the API and debugging your scripts. If you aspire to be a SketchUp plugins programmer, then getting familiar with the console is a good place to start.

In this tutorial we'll show you how to get to it and enter our first API commands.

The SketchUp Ruby Console The Ruby Console can be
used to explore the API
one command at a time.

Try this!

  1. Start SketchUp or SketchUp Pro.

  2. Open the Ruby Console (Window > Ruby Console).

  3. Type the following in the text input field at the bottom of the console:
    UI.beep
    

     

    This command invokes the beep method of the UI module to play a warning beep.

  4. Type the following in the text input field:
    UI.messagebox("Hello World")
    

     

  5. Type the following in the text input field to draw a line in SketchUp (press the Enter or Return key after each line).
    pt1 = [0, 0, 0] 
    pt2 = [10, 10, 0]
    model = Sketchup.active_model
    model.entities.add_line(pt1, pt2)
    

     

    The first line defines a variable called pt1 (point one) and assigns it an array of three values [0,0,0]. This is the starting Point3d for the line that will be drawn.

    The second line defines a variable called pt2 (point two) and assigns it an array of three values [10,10,0]. This is the ending Point3d for the line that will be drawn.

    The third line defines a variable which receives a reference to the currently active Model.

    The fourth line adds a Edge entity (from pt1 to pt2) to the currently active model. Go zoom in on the origin of your drawing and you should see our line:

    Our first line

Conclusion

Experiment with the commands above. Try showing a messagebox with a different string or drawing lines elsewhere in the model. A few other commands that are easy to run include UI.openURL, UI.inputbox, and Sketchup.send_action. Try reading the documentation on these methods and typing them in.

Now that you've seen the manual way to issue commands to the API, let's make a real plugin. Onward to the Hello World Tutorial.



Trimble Home
About Trimble - Privacy Policy - Contact Us