top of page

DWG Batch to JPEG Exporter for SketchUp

Automatically imports DWG files from a folder, sets a clean top-down view, and exports each one as a high-res JPEG with a white background.

DWG Batch to JPEG Exporter for SketchUp

Broken button... I'll fix it eventually...

require 'sketchup.rb'

require 'fileutils'


module DWG_JPEG_BatchExporter

  def self.run

    model = Sketchup.active_model

    view = model.active_view


    # Select root folder

    root = UI.select_directory(title: "Select Folder With DWG Files")

    return unless root


    dwg_paths = Dir.glob(File.join(root, '**', '*.dwg'))


    if dwg_paths.empty?

      UI.messagebox("No DWG files found.")

      return

    end


    dwg_paths.each do |dwg|

      puts "Processing: #{dwg}"


      begin

        # Clear model

        model.entities.clear!


        # Import DWG

        import_success = model.import(dwg, {

          :show_summary => false,

          :merge_coplanar_faces => true

        })


        unless import_success

          puts "  Failed to import: #{dwg}"

          next

        end


        # Set Top View + Parallel Projection

        cam = Sketchup::Camera.new(

          [0, 0, 1000],   # eye

          [0, 0, 0],      # target

          [0, 1, 0]       # up

        )

        cam.perspective = false

        view.camera = cam

        view.zoom_extents


        # Style: white background, no sky/ground, no shadows or axes

        opts = model.rendering_options

        opts["BackgroundColor"] = Sketchup::Color.new(255, 255, 255)

        opts["DisplaySky"] = false

        opts["DisplayGround"] = false

        opts["DisplayShadows"] = false

        opts["DisplayAxes"] = false

        opts["EdgeDisplayMode"] = 1  # Normal edges only


        # Export image with same base name

        base = File.basename(dwg, '.dwg')

        jpg_path = File.join(File.dirname(dwg), "#{base}.jpg")


        view.write_image({

          :filename => jpg_path,

          :width => 1920,

          :height => 1080,

          :antialias => true,

          :compression => 0.9

        })


        puts "  Exported JPEG: #{jpg_path}"


        model.entities.clear!

        GC.start


      rescue => e

        puts "  Error with #{dwg}: #{e.message}"

      end

    end


    UI.messagebox("Finished exporting all DWG files.")

  end

end


DWG_JPEG_BatchExporter.run


Description

This Ruby script automates the process of turning a folder full of DWG files into clean, high-contrast JPEG images using SketchUp. Once launched, you select a root folder and the script:

  • Recursively finds all .dwg files inside

  • Imports each one into a fresh SketchUp scene

  • Applies a consistent top-down, parallel projection camera

  • Sets the style to a white background with no shadows, sky, or axes for maximum clarity

  • Exports a 1920×1080 JPEG using the same name as the DWG file

  • Clears the model and repeats for the next file

The result is a batch of uniform, presentation-ready 2D images — ideal for documentation, client previews, or visual asset libraries.

bottom of page