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.
|
|
UI.beep
This command invokes the beep method of the UI module to play a warning beep.
UI.messagebox("Hello World")
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:
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.