How to set Focus to Mainwindow

No guarantees. English only. Window caption text may vary per language edition.

This code would be inside your class or module.
The Ruby standard library must be availble with “win32ole.so” file loadable. (This is provided with SketchUp 2014+. It gets complicated with older SketchUp versions.)

The SketchUp application window caption may have changed over time, see Doc: Sketchup::app_name

Could not find my old snippet, so I typed this out just a few minutes ago.

EDIT: Tested and works on SU2015 Pro with “Untitled” and titled model file.

EDIT (2019-01-28): SketchUp 2016 and higher add a space and the year to the window caption, so the code below will need to be edited to sniff out the version and add the year to the caption string.


require "win32ole"

def activate_window( caption = get_caption() )
  #
  wsh = WIN32OLE.new("WScript.Shell")
  wsh.AppActivate caption
  #
end ###

def get_caption()
  #
  if Sketchup.active_model.path.empty? # new model
    caption = "Untitled - SketchUp"
  else
    filename = File.basename(Sketchup.active_model.path)
    if Sketchup.is_pro?
      caption = "#{filename} - SketchUp Pro"
    else
      caption = "#{filename} - SketchUp"
    end
  end
  #
end ###

:bulb:


Ref: MSDN: Windows Script Host - AppActivate Method