How to run a Ruby script in SketchUp
Open the Ruby Console (Extensions › Developer › Ruby Console in SketchUp 2021.1 and newer, Window › Ruby Console in older versions), paste the code into the lower box and press Enter. For a script saved as a file, type load "/full/path/to/script.rb" in the console instead.
How to open the Ruby Console in SketchUp
The Ruby Console is built into SketchUp Pro and Studio on Mac and Windows. Where it lives depends on your version:
- SketchUp 2021.1 and newer: Extensions › Developer › Ruby Console.
- Before SketchUp 2021.1: Window › Ruby Console.
The menu path is the same on macOS and Windows. The console has two parts: the upper area shows output and errors, and the lower box is where you type or paste. Anything you paste into the upper area is ignored.
Try it with something harmless. Type Sketchup.version and press Enter. The console prints your version number, which also tells you the console is working.
Two console commands worth knowing: cls clears the output (it only works typed in the console, not inside a script file), and puts prints a value from your own code.
Pasting and running a short script
Copy the script, click in the lower box, paste, and press Enter. SketchUp runs it against the model in the front window and prints the last value, or the error.
Here is a read-only example. Select some geometry first, then paste it:
model = Sketchup.active_model
faces = model.selection.grep(Sketchup::Face)
puts "#{faces.size} faces selected"And one that lists every component definition in the model with how many copies it has:
Sketchup.active_model.definitions.each do |d|
next if d.group? || d.image?
puts "#{d.name}: #{d.instances.size}"
endScripts like this are how batch jobs get done, such as renaming hundreds of components or swapping a material everywhere.
A few things trip people up when pasting:
- The input box is small, but a pasted multi-line script goes in whole. Plain Enter runs it. To start a new line while typing, forum users suggest Ctrl+Enter.
- On SketchUp 2025 for Mac, some users report that Cmd+V sometimes pastes nothing. Right-click the box and choose Paste instead.
- Locals and methods you define vanish when SketchUp closes. For anything longer than a few lines, or anything you will run twice, save it as a file.
Loading a .rb file with load
Save the script as a plain text file ending in .rb (TextEdit on Mac needs Format › Make Plain Text first; any code editor is easier). Then load it from the console with its full path. Use forward slashes on both platforms:
# macOS
load "/Users/you/Desktop/count_faces.rb"
# Windows (forward slashes, not backslashes)
load "C:/Users/you/Desktop/count_faces.rb"load runs the file every time you call it, so you can edit the script, save, and load it again. It returns true when the file ran. If the path is wrong, the console prints a load error.
Backslashes in a Windows path cause trouble because Ruby reads them as escape characters inside double quotes. Forward slashes work everywhere.
Don't drop loose test scripts into the Plugins folder. Everything there runs each time SketchUp starts, so a half-finished script will run on startup too. Packaging a finished script properly is covered in how to make your own SketchUp extension.
Where is the SketchUp Plugins folder?
Each SketchUp version has its own Plugins folder in your user account. Replace 20XX with your version:
- macOS:
~/Library/Application Support/SketchUp 20XX/SketchUp/Plugins. The Library folder is hidden; in Finder, hold Option and open the Go menu to see it. - Windows:
C:\Users\<you>\AppData\Roaming\SketchUp\SketchUp 20XX\SketchUp\Plugins. You can type%AppData%\SketchUpin the File Explorer address bar to get close.
The quickest way to get the exact path is to ask SketchUp. Paste this into the Ruby Console:
Sketchup.find_support_file("Plugins")Install finished extensions through Extensions › Extension Manager › Install Extension rather than copying files by hand. SketchUp puts them in the right folder for you.
Undoing what a script did
Edit › Undo (Cmd+Z on Mac, Ctrl+Z on Windows) works on script changes, but how much it undoes depends on how the script was written.
A script that changes the model without an operation leaves many small undo steps behind. Undoing a script that touched 400 edges can mean pressing Cmd+Z 400 times, and it is easy to undo past your own last edit by accident.
A script wrapped in start_operation and commit_operation is one undo step with its own name in the Edit menu. This example hides the selected edges as one step called "Hide selected edges":
model = Sketchup.active_model
model.start_operation("Hide selected edges", true)
begin
model.selection.grep(Sketchup::Edge).each { |edge| edge.hidden = true }
model.commit_operation
rescue StandardError
model.abort_operation
raise
endThe true tells SketchUp not to redraw after every change, which makes big scripts much faster. The rescue part rolls everything back if the script fails halfway, so you are never left with half a change. When you get a script from a forum or a chatbot, check for this wrapper before you run it. If it's missing, ask for it or add it yourself.
Saving the model, writing files to disk and changes to other open models are not undoable, wrapper or not.
Is it safe to run Ruby scripts in SketchUp?
Only run code you trust. A Ruby script in SketchUp has the same access to your computer as SketchUp itself: it can delete files, overwrite your model on disk, or send data over the network. There is no sandbox.
- Save a copy of the model before running anything new on it.
- Read the script before you run it, or ask someone who can. Be wary of lines that mention
File,Dir,system,saveor a web address in a script that should only be editing geometry. - Try new code on a test model first.
Ruby only runs in the desktop apps. SketchUp Free (the web version) and SketchUp Go have no Ruby Console and cannot run scripts or extensions.
If you outgrow the built-in console, Ruby Console+ (by Aerilius, on SketchUcation) adds an editor, history and multi-line input. Its listing names SketchUp 2017 to 2022, and a 2024 forum thread reports it stopped working in SketchUp 2024, so check it against your version. Many people write scripts in a normal code editor and run them with load instead.
Skip the console: let an agent run the Ruby for you
The console loop (ask a chatbot for code, paste it, paste the error back) works, but the chatbot never sees your model. Using ChatGPT to write SketchUp Ruby scripts covers how to make that loop go better.
MakeIt4Me (our product) connects an AI agent on your computer (Claude, ChatGPT desktop, Cursor and others) to your open model. You describe the change. The agent writes the Ruby, runs it in the live model, reads any error, takes a screenshot to check the result and tries again until it's right.
- Every change it makes is one named undo step in Edit › Undo, even if it adds dozens of pieces.
- If its code fails partway, the change is rolled back automatically.
- It can inspect the model with read-only code first, so it works from your real component names and materials rather than guesses.
It still runs Ruby, so the same limits apply: file saves and anything written to disk can't be undone. See how it compares with pasting chatbot code at MakeIt4Me vs pasting ChatGPT code.
Questions
Where did the Ruby Console go in SketchUp?
From SketchUp 2021.1 it moved to Extensions › Developer › Ruby Console. Before that it is Window › Ruby Console.
Can I run Ruby scripts in SketchUp Free or SketchUp Go?
No. Ruby scripts and extensions need SketchUp Pro or Studio on Mac or Windows.
Why does my pasted script give a syntax error?
Usually a line got mangled when it was copied, for example curly quotes from a web page or a chat app instead of straight ones. Paste into a plain text editor first, save it as a .rb file and run it with load.
How do I run a script automatically every time SketchUp starts?
Anything in the Plugins folder runs at startup. The tidy way to do that is to package the script as an extension, which also lets you switch it off in the Extension Manager. See how to make your own SketchUp extension.