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:
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!')
SketchUp looks in its Plugins folder for ruby scripts every time it starts.
If you haven't already done so, install SketchUp or SketchUp Pro.
PC folks: Use Windows Explorer to locate your Plugins folder. It should be something like...
c:\Program Files\Google\Google SketchUp [n]\Plugins
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.)
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.
Congratulations! You've successfully written your first SketchUp Plugin.
Extra Credit:
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.)
Try making a few line script that asks the user, "What is your name?" and then replies, "Hello, YOURNAME!" (hint: you'll want to copy and paste some code from the UI.inputbox documentation)