top of page
TrimbleR-Horiz-RGB-Blue.jpg
SketchUp-Horizontal-RGB-120pxl_0.png

Basic Development Environment

In the previous article we wrote code directly into the Ruby console. Now we'll look into where the code can be stored persistently, to allow a project to grow over time. This article is mostly aimed at beginners to coding, but parts of it may be useful for existing developers new to SketchUp.

Code Editor

To start with, use a code editor to work on the code instead of writing it directly to the Ruby Console. This allows the code to be saved so it can be worked on and used over time. Code editors also have useful features such as syntax highlighting, auto-complete and more.

Notepad++ is a basic code editor for Windows with pretty much everything you need, no more, no less, a bit like SketchUp for code. Mac ships with TextEdit. Visual Studio Code and Sublime are popular editors, working on both Windows and Mac.

Project Folder

Many tinkerers start by saving their scripts to the SketchUp Plugins folder. It allows the script to load automatically when SketchUp starts but has a few drawbacks. Firstly, it mixes the files of the project with those of other projects, as well as with the extensions you've downloaded. Secondly, it gives no natural place to put files that are part of the project but not used by SketchUp itself, such as version control (more on that further down), test models, screenshots for Extension Warehouse, readme, build scripts and more.

A better approach is to set up a custom folder where you store your SketchUp extension projects. This could be in your document folder.

Win: C:/Users/Jane Doe/Documents/SketchUp Extensions
Mac: ~/Documents/SketchUp Extensions

Here you can have a separate folder for each project.

Win: C:/Users/Jane Doe/Documents/SketchUp Extensions/Cube Maker
Mac: ~/Documents/SketchUp Extensions/Cube Maker

Inside the project folders you typically have yet another folder emulating a nice little corner of the Plugins folder. Everything that's consumed by SketchUp goes here. The content of this folder is also what you make an RBZ file from when you are later ready to share your extension. Usually this folder is named "src".

Win: C:/Users/Jane Doe/Documents/SketchUp Extensions/Cube Maker/src"
Mac: ~/Documents/SketchUp Extensions/Cube Maker/src

Things not used by SketchUp (developer documentation, Extension Warehouse screenshots etc) goes outside of the "src" folder.

To make your files load when SketchUp starts, as if they were in the Plugins folder, you can add this loader script to the Plugins folder.

# loader.rb

# Change to match your SketchUp extension source location
pattern = "C:/Users/Jane/Documents/Source/SketchUp Extensions/*/src"
Dir.glob(pattern).each do |dir|
  $LOAD_PATH << dir
  Dir.glob("#{dir}/*.rb").each { |file| require file }
end

The Plugins folder is located at "%appdata%/SketchUp/SketchUp 2025/SketchUp/Plugins/" on Windows and "\~/Library/Application Support/SketchUp 2025/SketchUp/Plugins/" on Mac. Replace the year with that of your SketchUp version.

Another approach is to use ThomThom's Extension Sources. This extension does the same job as the above script, but also it lets you reload the Ruby files without restarting SketchUp, and disable the loading of projects you don't actively work on.

Script Structure

When a script loads automatically with SketchUp, it shouldn't start doing things to the model right away. Make sure your code is wrapped in methods and the methods triggered from the UI. The only code to run directly as SketchUp starts is for setting up the UI.

# Bad
# The box is drawn as SketchUp starts
Sketchup.active_model.start_operation("Draw Cube"true)
face = Sketchup.active_model.entities.add_face(
  [000], [1.m00], [1.m1.m0], [01.m0]
)
face.reverse! unless face.normal.samedirection?(Z_AXIS)
face.pushpull(1.m)
Sketchup.active_model.commit_operation

# Good
# The box is drawn once the user asks for it
# The UI is created as SketchUp starts
def draw_box
  Sketchup.active_model.start_operation("Draw Cube"true)
  face = Sketchup.active_model.entities.add_face(
    [000], [1.m00], [1.m1.m0], [01.m0]
  )
  face.reverse! unless face.normal.samedirection?(Z_AXIS)
  face.pushpull(1.m)
  Sketchup.active_model.commit_operation
end
UI.menu("Extensions").add_item("Draw Box") { draw_box }

To avoid clashes with other scripts - someone else could have a method for drawing a box - wrap everything you define under your own unique namespace. Often an outer personal namespace and an inner project namespace are used.

module JaneDoe
  module BoxMaker
    # Code goes here...

    def self.draw_box
      # ...
    end
  end
end

Note that methods within modules need to be defined on self.

Git - Version Control

Version control is like a series of backups of your code. It lets you roll back if something goes wrong (very useful for beginners!) but also to later go back and follow your own train of thoughts. It helps you compare different versions to see when and where a bug was introduced, and it lets you experiment in isolation without risking breaking anything. It's also the foundation for collaborating with other developers, and helps to sync your code between machines.

Git is the most common form of version control. You can use it from the command line or use a graphical user interface such as SourceTree or GitHub Desktop.

With every extension project isolated into its own folder as shown above, you can make that folder a Git repository. Whenever you've made a meaningful change you can stage your changed files, write a message describing what you did and why and commit it. For new features or experiments, it's useful to start new branches. When the feature is completed you can merge it back to the main branch. You can push to a remote server both for backup, for collaboration or to continue the work from another computer. GitHub is a popular service for hosting Git repositories.

You can learn more about Git on their website.

Rubocop - Static Code Analysis

Static code analysis can be used to scan through your code to find potential problems and offer solutions to them. Rubocop is a generic static code analyzer for Ruby and rubocop-sketchup an extension that specifically helps with SketchUp Extension related issues.

Using sketchup-rubocop can help detect common errors yourself so you can fix them before submitting to Extension Warehouse for review. This saves time both for you and the reviewers.

You can start a command line prompt in your project folder and run the rubocop commands from there. In this folder you can also put the "rubocop.yaml" config file.

Next Step

Once you have your development environment set up, maybe it's time to look into some slightly more advanced drawing, how to write a valid SketchUp Extension, or to look into some example snippets for ideas.

bottom of page