Hello World

In this example we will write a one-line Ruby script that shows a messagebox. When we're done it will look something like this:

Screenshot 3 of SketchUp Ruby API Hello World

Step 1: Create a script file

Using your favorite text editor (Notepad on Windows or Textedit on the Mac are fine), create a new file and type this exact line of code into it:

UI.messagebox('Hello World!')

 


Step 2: Save it in the Plugins folder

SketchUp looks in its Plugins folder for ruby scripts every time it starts.

  1. If you haven't already done so, install SketchUp or SketchUp Pro.
  2. PC folks: Use Windows Explorer to locate your Plugins folder. It should be something like...
    c:\Program Files\Google\Google SketchUp [n]\Plugins
  3. Mac folks: Use Finder. It should be something like...
    /Library/Application Support/Google SketchUp [n]/plugins
    ...or like...
    /Library/Application Support/Google SketchUp [n]/SketchUp/plugins

Save the text file created in step one into this Plugins folder as helloworld.rb. (Files with .rb or .rbs extensions are the ones that get loaded. Any other extension will be ignored.)

Step 3: Say Hello!

To run our plugin we simply need to start Sketchup (or restart, if it's already open.) If everything went well you'll see "Hello World!" every time you start the program.

This one line of code uses the UI module's messagebox method to show the alert box. UI is one of the "big three" modules that provide hooks for manipulating SketchUp with Ruby. The other modules are SketchUp and Geom. We'll learn more as we go through the other tutorials.

Conclusion

Congratulations! You've successfully written your first SketchUp Plugin.

Try changing the message from "Hello World!" to something else and saving the file. Reload your script by closing and restarting SketchUp. (To "uninstall" the script, simply delete the text file or move it outside your Plugins folder.)

Ready for a more interesting example? Move on to the Creating Geometry Tutorial.


Trimble Home
About Trimble - Privacy Policy - Contact Us