Debugging SketchUp 2019 Plugins with VSCode

2025-02-18·
XIETU
XIETU
· 2 min read · 阅读量

My plugin name: sine_points.rb

Step-by-Step Guide

1. Download SURubyDebugger.dll for SketchUp 2019

This library enables debugging of SketchUp Ruby scripts, allowing you to set breakpoints, step through code, inspect variables, and evaluate expressions. Download from GitHub

Select the version matching your SketchUp installation (2019 in this case) and place it in the SketchUp root directory (e.g., C:\Program Files\SketchUp\SketchUp 2019)

Library

2. Install VSCode

Download VSCode. After installation, change the UI language to Chinese by opening the Command Palette (Ctrl+Shift+P), searching for “Language”, selecting “Configure Display Language”, and choosing Chinese.

VSCode
VSCode

3. Install Ruby Extension in VSCode

  1. Click the Extensions icon (four squares) in the activity bar or use Ctrl+Shift+X to open the extensions marketplace. Search for “Ruby”.

    Ruby

  2. You’ll see a deprecation notice recommending Ruby LSP - DO NOT install Ruby LSP as it will cause configuration issues with launch.json.

    Warning

Here’s what happens if you install Ruby LSP (shows “property not allowed” errors) - I spent two days troubleshooting this:

Error

  1. Download the Ruby extension manually from GitHub

    Download
    Go to https://github.com/rubyide/vscode-ruby/releases
    Releases

  2. Install the extension locally in VSCode

    Install

4. Configure tasks.json

This file defines build tasks in the .vscode folder, allowing automation of commands like compiling code or running tests.

  1. Create default build task
    Task

Use template to create tasks.json

Template
Select “Others”
Others
This automatically creates tasks.json in the .vscode folder
Created

  1. Copy configuration from this guide and paste it in
    Guide

Here’s the code, modified for Windows with port configuration:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Start SketchUp with Debugging",
      "type": "shell",
      "windows": {
        "command": "&'C:/Program Files/SketchUp/SketchUp 2019/SketchUp.exe' -rdebug 'ide port=6123 wait'"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": [],
      "detail": "Launch SketchUp and wait for debugger connection"
    }
  ]
}

5. Configure launch.json

This file defines debugger behavior including debug type, launch mode, and environment variables.

Create debug configuration

Debug
Select Ruby debugger
Ruby
Choose “Listen for rdebug-ide”
Listen
Default settings
Default

  1. Copy configuration from this guide
    Guide

Modified code with port configuration:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for rdebug-ide",
      "type": "Ruby",
      "request": "attach",
      "cwd": "${workspaceRoot}",
      "remoteHost": "127.0.0.1",
      "remotePort": "6123",
      "remoteWorkspaceRoot": "${workspaceRoot}"
    }
  ]
}

6. Synchronize File Paths

My plugin path (F:\MySketchUpPlugin) differs from SketchUp’s plugin directory (C:\Users...\Plugins).

(Solution: Create dev_loader.rb in SketchUp plugins folder , Principle: SketchUp automatically loads all .rb files in the Plugins directory upon startup. The dev_loader.rb script adds your development directory to Ruby’s load path and actively loads the specified file.)

# Location: C:\Users\...\Plugins\dev_loader.rb
dev_path = "F:/MySketchUpPlugin" # Your actual path

# Add dev directory to load path
$LOAD_PATH.unshift(dev_path) unless $LOAD_PATH.include?(dev_path)

# Auto-load main plugin
require File.join(dev_path, 'sine_points.rb')

puts "Dev mode activated: Loading plugin from #{dev_path}"

7. Testing Workflow

  1. Run build task (Ctrl+Shift+B) - SketchUp will appear frozen
    Task

Check port status:

netstat -an | find "6123"

Port
This indicates a service is listening on port 6123 across all network interfaces (0.0.0.0:6123 means the port is open to all IP addresses). This confirms SketchUp has successfully launched and is actively listening on the designated debugging port.

  1. Start debugger (Ctrl+Shift+D) - select “Listen for rdebug-ide”

Debug
Running

Check port connection:

netstat -an | find "6123"

调试
This shows SketchUp is listening on port 6123 across all network interfaces (0.0.0.0:6123), with an established connection. This confirms the SketchUp debugging service is running, where both connections represent the same TCP session from different perspectives.

  1. Set breakpoints and test

Breakpoint

Breakpoint
Plugin
Plugin
Triggered
Triggered
Hit
Hit
Success
Success

8. Happy Coding!

AI tools have greatly expanded creative potential for individual developers!