Using ChatGPT to write SketchUp Ruby scripts

ChatGPT can write useful SketchUp Ruby if you tell it your SketchUp version, what is selected and which units you mean, and ask it to wrap the change in one undo operation. Paste the script into Extensions › Developer › Ruby Console, run it on a saved copy, and paste any error back to ChatGPT.

How to ask ChatGPT for a SketchUp script

ChatGPT has read a lot of SketchUp Ruby, but it can't see your model. Everything it knows about your file comes from your prompt. Put these in it:

  • Your SketchUp version and platform. "SketchUp Pro 2025 on Windows." Some methods only exist in newer versions.
  • What the script should act on. "The current selection", "every component named Chair" or "the whole model". Say whether it should reach inside groups and components.
  • Units. SketchUp stores every length in inches internally, whatever your template shows. If you think in millimeters, say so and ask it to use .mm (for example 2400.mm).
  • One undo step. Ask it to wrap the change in model.start_operation("Name", true) and model.commit_operation, and to call model.abort_operation if anything fails.
  • A summary at the end. "Print how many objects you changed." A count tells you at once whether it did what you meant.

A prompt that works well:

"Write a SketchUp Ruby script for SketchUp 2025. For the current selection, including faces inside selected groups and components, set every face's material to a material named Walnut (create it if missing). Wrap it in one start_operation with abort on error. Print the number of faces changed. Only use methods from the official SketchUp Ruby API."

The script that comes back should look roughly like this:

model = Sketchup.active_model
model.start_operation("Paint selection", true)
begin
  mat = model.materials["Walnut"] || model.materials.add("Walnut")
  count = 0
  paint = lambda do |ents|
    ents.to_a.each do |e|
      if e.is_a?(Sketchup::Face)
        e.material = mat
        count += 1
      elsif e.is_a?(Sketchup::Group) || e.is_a?(Sketchup::ComponentInstance)
        paint.call(e.definition.entities)
      end
    end
  end
  paint.call(model.selection)
  model.commit_operation
  puts "Painted #{count} faces"
rescue => err
  model.abort_operation
  raise err
end

Note that painting inside a component changes its definition, so every copy of that component changes too. That is usually what you want, but ask ChatGPT to call make_unique first if it isn't.

How to run a ChatGPT script in SketchUp

The short version:

  1. Save your model, or work on a copy.
  2. Open Extensions › Developer › Ruby Console (SketchUp 2021.1 and newer; older versions have it under Window › Ruby Console). The path is the same on Mac and Windows.
  3. Paste the script into the input box and press Enter.
  4. Check the output line and look at the model. If it's wrong, use Edit › Undo (Cmd+Z on Mac, Ctrl+Z on Windows).

The Ruby Console only exists in desktop SketchUp. SketchUp Free (web), SketchUp Go and the iPad app can't run scripts. For loading .rb files, multi-line scripts and more on undo, see how to run a Ruby script in SketchUp.

Common mistakes ChatGPT makes with the SketchUp API

Most broken scripts fail in one of a few familiar ways. Knowing them makes the error messages much easier to read.

  • Made-up methods. It invents names that sound right, like face.set_color or model.find_by_name. The console says undefined method. Ask it to check the method against ruby.sketchup.com or use a different approach.
  • Ignoring groups and components. model.entities is only the top level. Geometry inside a group or component lives in its definition.entities, so a script that never goes inside finds nothing, or only half the model.
  • Inches vs millimeters. A script meant to move something 100 mm that writes 100 moves it 100 inches. Lengths need .mm, .cm or .m, and output needs .to_mm if you want millimeters.
  • No undo operation. Without start_operation, each change can become its own undo step. A script that touches 200 objects can need 200 undos, and one that fails halfway leaves half the change behind.
  • Changing a collection while looping over it. Erasing or adding entities inside entities.each skips items or behaves oddly. The API docs say to iterate over a copy: entities.to_a.each.
  • Editing every copy by accident. Changing a component's definition changes all its instances. Editing a group's entities makes that group unique, but editing through group.definition does not.
  • Using the wrong "current" context. model.entities is the top level even when you're inside a group. For "where I'm working now", it should use model.active_entities.

How to fix a script that fails

When the console shows an error, copy the whole message, including the line number, and paste it back to ChatGPT with one sentence about what you saw. "It ran without errors but nothing changed" is useful too.

A few tips make each round count:

  • Ask for a read-only version first: "Don't change anything. Print the names and counts of what you would change." That tells you whether it is finding the right objects.
  • If it keeps guessing methods, paste the relevant page from ruby.sketchup.com into the chat.
  • If the script ran but was wrong, undo it before you run the next version, or the second run starts from a half-changed model.
  • Describe your model's structure when it matters: "The chairs are components nested inside a group called Dining."

When this approach stops working well

Pasting code works for short, clear jobs: rename these, recolor those, count something. It gets harder as the job grows, for one reason: ChatGPT never sees your model or the result of its code. It is writing for a model it imagines.

You'll notice it when:

  • The fix for one error causes another and you're on round five.
  • The job depends on what the geometry looks like, like "line the shelves up with the window", which code alone can't judge.
  • The script works on a test object but not on your real model, because your nesting or names differ from what it assumed.

At that point either break the job into smaller scripts, or use a setup where the AI can run code in your model and look at the result itself. The comparison of pasting ChatGPT code against an agent that sees the model covers the trade-offs. If a script turns out to be something you'll reuse, you can turn it into an extension.

Let ChatGPT run the script in your model itself

MakeIt4Me (our product) is a SketchUp extension that lets the ChatGPT desktop app work on your open model directly. You install the .rbz in SketchUp, then upload the MakeIt4Me plugin archive under Plugins in ChatGPT desktop. Start the task in Work mode, since plugins only run there.

Instead of you copying code back and forth, ChatGPT runs its Ruby in the live model, reads its own errors, takes a viewport screenshot to check the result and tries again. Every change is one named step in Edit › Undo, and code that fails is rolled back. It also comes with skills that teach the agent SketchUp's Ruby traps, including the ones above.

It needs SketchUp Pro or Studio 2017 or newer on Mac or Windows, with ChatGPT desktop on the same computer. It doesn't work in the ChatGPT website or mobile app. It's a one-time purchase, and your ChatGPT plan is billed separately. Some requests still take a couple of rounds; the difference is that ChatGPT does the rounds.

Questions

Can ChatGPT write SketchUp Ruby scripts?

Yes, and short ones often work first time. Longer scripts usually need a round or two of pasting errors back, because ChatGPT can't see your model or run the code.

Is it safe to run a ChatGPT script in SketchUp?

Read it first and run it on a saved copy. Ruby in SketchUp can do anything Ruby can, including deleting files, so don't run code you don't understand from a source you don't trust. Ask ChatGPT to explain each line if you're unsure.

Why does my script say undefined method?

Usually ChatGPT invented a method or used one from a newer SketchUp version. Paste the error back, tell it your SketchUp version and ask it to use only methods from the official API docs.

Why did my script only change some objects?

Most likely the rest are inside groups or components, and the script only looked at the top level. Ask for a version that goes into each group's and component's definition.