Module: AMS::Sketchup

Defined in:
Documentation/ams/sketchup.rb

Overview

Note:

Windows only!

The Sketchup namespace contains functions that allow user to get various information on SketchUp window and its child windows.

Since:

  • 2.0.0

Class Method Summary collapse

Class Method Details

.activateBoolean Also known as: bring_to_top

Set main window active.

Since:

  • 2.0.0


126
127
# File 'Documentation/ams/sketchup.rb', line 126

def activate
end

.activate_scenes_bar_tab(tab_index) ⇒ Boolean

Activate (highlight) scene tab without activating the associated page.

Since:

  • 3.5.0


193
194
# File 'Documentation/ams/sketchup.rb', line 193

def activate_scenes_bar_tab(tab_index)
end

.add_observer(object) ⇒ Boolean

Note:

An observer can be a class, module, or a class instance. Your observer will work as long as the callback methods are public.

Note:

Your observer is not supposed to contain every callback method from the observers list. You may include/elude those as you wish.

Note:

A unique extension swp or swo is added in front of each observer method. SWP stands for Sketchup Window Procedure, and SWO stands for Sketchup Window Observer. Both SWP and SWO events are capable to monitor window messages, but SWP events are also capable to make decisions to the message, whether or not the message should interact with SketchUp window. If the return value for the SWP callback method is 1, the message associated with the event will not interact with SketchUp window. For example, returning 1 in the swp_on_key_down event will prevent the key from interacting with SketchUp window, which means any shortcut associated with such key will not be triggered. SWP events may come in handy for extensions that want more control over SketchUp.

Add object to the observers list.

Examples:

Adding observer from a class instance:

class MySketchupObserver
  def swo_on_switch_full_screen(state)
    puts 'Main window was set full screen!' if state
  end
end # module MySketchupObserver
AMS::Sketchup.add_observer(MySketchupObserver.new)

Adding observer from a module:

module MySketchupObserver
  def self.swo_on_switch_full_screen(state)
    puts 'Main window was set full screen!' if state
  end
end # module MySketchupObserver
AMS::Sketchup.add_observer(MySketchupObserver)

Another way to add observer from a module:

module MySketchupObserver
  class << self
    def swo_on_switch_full_screen(state)
      puts 'Main window was set full screen!' if state
    end
  end # class << self
end # module MySketchupObserver
AMS::Sketchup.add_observer(MySketchupObserver)

See Also:

Since:

  • 2.0.0


514
515
# File 'Documentation/ams/sketchup.rb', line 514

def add_observer(object)
end

.closeBoolean

Note:

This behaves the same way as clicking the 'X' button.

Close current SketchUp application.

Since:

  • 2.0.0


469
470
# File 'Documentation/ams/sketchup.rb', line 469

def close
end

.close_dialogsFixnum

Note:

Ignored dialogs won't be included in this operation.

Close all dialogs and trays.

Since:

  • 2.0.0


283
284
# File 'Documentation/ams/sketchup.rb', line 283

def close_dialogs
end

.close_toolbarsFixnum

Close all floating toolbars.

Since:

  • 2.0.0


321
322
# File 'Documentation/ams/sketchup.rb', line 321

def close_toolbars
end

.close_traysFixnum

Close all trays.

Since:

  • 3.5.0


310
311
# File 'Documentation/ams/sketchup.rb', line 310

def close_trays
end

.find_child_window_by_caption(parent_handle, caption, include_sub_childs = false, full_match = true, case_sensitive = true) ⇒ Fixnum?

Note:

This function will iterate through windows belonging to the current SketchUp process only. All windows belonging to a different process or a different SketchUp application will not be searched.

Find handle to a child window with a specific caption.

Since:

  • 3.0.0


380
381
# File 'Documentation/ams/sketchup.rb', line 380

def find_child_window_by_caption(parent_handle, caption, include_sub_childs = false, full_match = true, case_sensitive = true)
end

.find_child_window_by_class_name(parent_handle, class_name, include_sub_childs = false, full_match = true, case_sensitive = true) ⇒ Fixnum?

Note:

This function will iterate through windows belonging to the current SketchUp process only. All windows belonging to a different process or a different SketchUp application will not be searched.

Find handle to a child window with a specific class name.

Since:

  • 3.0.0


411
412
# File 'Documentation/ams/sketchup.rb', line 411

def find_child_window_by_class_name(parent_handle, class_name, include_sub_childs = false, full_match = true, case_sensitive = true)
end

.find_window_by_caption(caption, full_match = true, case_sensitive = true) ⇒ Fixnum?

Note:

This function will iterate through windows belonging to the current SketchUp process only. All windows belonging to a different process or a different SketchUp application will not be searched.

Find handle to a window with a specific caption.

Since:

  • 3.0.0


363
364
# File 'Documentation/ams/sketchup.rb', line 363

def find_window_by_caption(caption, full_match = true, case_sensitive = true)
end

.find_window_by_class_name(class_name, full_match = true, case_sensitive = true) ⇒ Fixnum?

Note:

This function will iterate through windows belonging to the current SketchUp process only. All windows belonging to a different process or a different SketchUp application will not be searched.

Find handle to a window with a specific class name.

Since:

  • 3.0.0


394
395
# File 'Documentation/ams/sketchup.rb', line 394

def find_window_by_class_name(class_name, full_match = true, case_sensitive = true)
end

.get_active_dialogsArray<Fixnum>

Note:

Ignored dialogs are not included in this list.

Get all used pop-up windows of the current SketchUp application.

Since:

  • 2.0.0


423
424
# File 'Documentation/ams/sketchup.rb', line 423

def get_active_dialogs
end

.get_active_toolbarsArray<Fixnum>

Note:

Ignored toolbars are not included in this list.

Get all used floating toolbars.

Since:

  • 2.0.0


441
442
# File 'Documentation/ams/sketchup.rb', line 441

def get_active_toolbars
end

.get_captionString

Get main window title text.

Since:

  • 2.0.0


452
453
# File 'Documentation/ams/sketchup.rb', line 452

def get_caption
end

.get_dialogsArray<Fixnum>

Note:

Ignored dialogs are not included in this list.

Get all pop-up windows of the current SketchUp application.

Since:

  • 2.0.0


417
418
# File 'Documentation/ams/sketchup.rb', line 417

def get_dialogs
end

.get_executable_pathString

Get full path to SketchUp.exe.

Since:

  • 2.0.0


15
16
# File 'Documentation/ams/sketchup.rb', line 15

def get_executable_path
end

.get_executalbe_nameString

Get executable name of this application. In most cases it would be “SketchUp.exe”.

Since:

  • 3.1.0


22
23
# File 'Documentation/ams/sketchup.rb', line 22

def get_executalbe_name
end

.get_main_windowFixnum

Get handle to the main window of the current SketchUp application.

Since:

  • 2.0.0


42
43
# File 'Documentation/ams/sketchup.rb', line 42

def get_main_window
end

.get_menu_barFixnum

Get handle to the menu bar of the main window.

Since:

  • 2.0.0


47
48
# File 'Documentation/ams/sketchup.rb', line 47

def get_menu_bar
end

.get_module_handleFixnum

Get module handle to the current SketchUp application.

Since:

  • 2.0.0


10
11
# File 'Documentation/ams/sketchup.rb', line 10

def get_module_handle
end

.get_other_main_windowsArray<Fixnum>

Get handles to all SketchUp main windows, except for the current one.

Since:

  • 3.1.0


526
527
# File 'Documentation/ams/sketchup.rb', line 526

def get_other_main_windows
end

.get_process_idFixnum

Get process id of the current SketchUp application.

Since:

  • 2.0.0


32
33
# File 'Documentation/ams/sketchup.rb', line 32

def get_process_id
end

.get_registry_pathString

Get registry path of the current SketchUp application.

Since:

  • 2.0.0


27
28
# File 'Documentation/ams/sketchup.rb', line 27

def get_registry_path
end

.get_scenes_barFixnum

Get handle to the scenes bar of the main window.

Since:

  • 2.0.0


62
63
# File 'Documentation/ams/sketchup.rb', line 62

def get_scenes_bar
end

.get_status_barFixnum

Get handle to the status bar of the main window.

Since:

  • 2.0.0


57
58
# File 'Documentation/ams/sketchup.rb', line 57

def get_status_bar
end

.get_thread_idFixnum

Get thread id of the current SketchUp application.

Since:

  • 2.0.0


37
38
# File 'Documentation/ams/sketchup.rb', line 37

def get_thread_id
end

.get_toolbar_containersArray<Fixnum>

Get handles to the four toolbar containers of the main window.

Since:

  • 2.0.0


68
69
# File 'Documentation/ams/sketchup.rb', line 68

def get_toolbar_containers
end

.get_toolbarsArray<Fixnum>

Note:

Ignored toolbars are not included in this list.

Get all floating toolbars of the current SketchUp application.

Since:

  • 2.0.0


435
436
# File 'Documentation/ams/sketchup.rb', line 435

def get_toolbars
end

.get_viewportFixnum

Get handle to the view window of the main window.

Since:

  • 2.0.0


52
53
# File 'Documentation/ams/sketchup.rb', line 52

def get_viewport
end

.get_viewport_centerArray<Fixnum>

Get viewport center in screen coordinates.

Since:

  • 2.0.0


270
271
# File 'Documentation/ams/sketchup.rb', line 270

def get_viewport_center
end

.get_viewport_originArray<Fixnum>

Get upper-left corner of the view window in screen coordinates.

Since:

  • 2.0.0


259
260
# File 'Documentation/ams/sketchup.rb', line 259

def get_viewport_origin
end

.get_viewport_rectArray<Fixnum>

Get upper-left and lower-right corners of the view window in screen coordinates, relative to the upper-left corner of the screen.

Since:

  • 2.0.0


254
255
# File 'Documentation/ams/sketchup.rb', line 254

def get_viewport_rect
end

.get_viewport_sizeArray<Fixnum>

Note:

This is same as view.vp_width and view.vp_height.

Get width and height of the view window in pixels.

Since:

  • 2.0.0


265
266
# File 'Documentation/ams/sketchup.rb', line 265

def get_viewport_size
end

.get_visible_dialogsArray<Fixnum>

Note:

Ignored dialogs are not included in this list.

Get all visible pop-up windows of the current SketchUp application.

Since:

  • 2.0.0


429
430
# File 'Documentation/ams/sketchup.rb', line 429

def get_visible_dialogs
end

.get_visible_toolbarsArray<Fixnum>

Note:

Ignored toolbars are not included in this list.

Get all visible floating toolbars of the current SketchUp application.

Since:

  • 2.0.0


447
448
# File 'Documentation/ams/sketchup.rb', line 447

def get_visible_toolbars
end

.ignore_dialog(handle) ⇒ Boolean

Elude dialog from the show_dialogs and close_dialogs operations.

Since:

  • 2.0.0


297
298
# File 'Documentation/ams/sketchup.rb', line 297

def ignore_dialog(handle)
end

.ignore_toolbar(handle) ⇒ Boolean

Elude toolbar from the show_toolbars and close_toolbars operations.

Since:

  • 3.0.0


338
339
# File 'Documentation/ams/sketchup.rb', line 338

def ignore_toolbar(handle)
end

.include_dialog(handle) ⇒ Boolean

Note:

By default, all dialogs are included in the show/hide/close dialogs operation. This method is used to remove dialog from the ignore list.

Include dialog in the show_dialogs and close_dialogs operations.

Since:

  • 2.0.0


291
292
# File 'Documentation/ams/sketchup.rb', line 291

def include_dialog(handle)
end

.include_toolbar(handle) ⇒ Boolean

Note:

By default, all toolbars are included in the show/hide/close toolbars operation. This method is used to remove toolbar from the ignore list.

Include toolbar in the show_toolbars and close_toolbars operations.

Since:

  • 3.0.0


331
332
# File 'Documentation/ams/sketchup.rb', line 331

def include_toolbar(handle)
end

.is_active?Boolean

Determine whether the current active window belongs to the current SketchUp application.

Since:

  • 2.0.0


349
350
# File 'Documentation/ams/sketchup.rb', line 349

def is_active?
end

.is_full_screen?Boolean

Determine whether main window is full screen.

Since:

  • 2.0.0


91
92
# File 'Documentation/ams/sketchup.rb', line 91

def is_full_screen?
end

.is_main_window_active?Boolean

Determine whether SketchUp main window is active.

Since:

  • 2.0.0


343
344
# File 'Documentation/ams/sketchup.rb', line 343

def is_main_window_active?
end

.is_maximized?Boolean

Determine whether main window is maximized.

Since:

  • 2.0.0


101
102
# File 'Documentation/ams/sketchup.rb', line 101

def is_maximized?
end

.is_menu_bar_set?Boolean

Determine whether menu bar is set.

Since:

  • 2.0.0


139
140
# File 'Documentation/ams/sketchup.rb', line 139

def is_menu_bar_set?
end

.is_minimized?Boolean

Determine whether main window is minimized.

Since:

  • 2.0.0


111
112
# File 'Documentation/ams/sketchup.rb', line 111

def is_minimized?
end

.is_restored?Boolean

Determine whether main window is restored.

Since:

  • 2.0.0


121
122
# File 'Documentation/ams/sketchup.rb', line 121

def is_restored?
end

.is_scenes_bar_empty?Boolean

Determine whether scenes bar is empty. Scenes bar is empty if there are no pages in the model.

Since:

  • 2.0.0


186
187
# File 'Documentation/ams/sketchup.rb', line 186

def is_scenes_bar_empty?
end

.is_scenes_bar_filled?Boolean

Determine whether scenes bar is filled. Scenes bar is filled if there is at least one page in the model.

Since:

  • 2.0.0


180
181
# File 'Documentation/ams/sketchup.rb', line 180

def is_scenes_bar_filled?
end

.is_scenes_bar_visible?Boolean

Determine whether scenes bar is visible.

Since:

  • 2.0.0


174
175
# File 'Documentation/ams/sketchup.rb', line 174

def is_scenes_bar_visible?
end

.is_status_bar_visible?Boolean

Determine whether status bar is visible.

Since:

  • 2.0.0


162
163
# File 'Documentation/ams/sketchup.rb', line 162

def is_status_bar_visible?
end

.is_toolbar_container_empty?(bar) ⇒ Boolean

Determine whether toolbar container(s) is/are empty.

Since:

  • 2.0.0


248
249
# File 'Documentation/ams/sketchup.rb', line 248

def is_toolbar_container_empty?(bar)
end

.is_toolbar_container_filled?(bar) ⇒ Boolean

Determine whether toolbar container(s) is/are filled.

Since:

  • 2.0.0


235
236
# File 'Documentation/ams/sketchup.rb', line 235

def is_toolbar_container_filled?(bar)
end

.is_toolbar_container_visible?(bar) ⇒ Boolean

Determine whether toolbar container(s) is/are visible.

Since:

  • 2.0.0


222
223
# File 'Documentation/ams/sketchup.rb', line 222

def is_toolbar_container_visible?(bar)
end

.is_viewport_border_set?Boolean

Determine whether viewport border is set.

Since:

  • 2.0.0


150
151
# File 'Documentation/ams/sketchup.rb', line 150

def is_viewport_border_set?
end

.maximizeBoolean

Set main window maximized.

Since:

  • 2.0.0


96
97
# File 'Documentation/ams/sketchup.rb', line 96

def maximize
end

.minimizeBoolean

Set main window minimized.

Since:

  • 2.0.0


106
107
# File 'Documentation/ams/sketchup.rb', line 106

def minimize
end

.refreshBoolean

Refresh the current SketchUp application.

Since:

  • 2.0.0


463
464
# File 'Documentation/ams/sketchup.rb', line 463

def refresh
end

.remove_observer(object) ⇒ Boolean

Remove object from the observers list.

Since:

  • 2.0.0


520
521
# File 'Documentation/ams/sketchup.rb', line 520

def remove_observer(object)
end

.restoreBoolean

Set main window to normal placement.

Since:

  • 2.0.0


116
117
# File 'Documentation/ams/sketchup.rb', line 116

def restore
end

.send_user_message(receiver_handle, id, user_data) ⇒ Boolean

Note:

If a destination window that a message is sent to by this function has an active swo_on_user_message observer, in most cases, it will receive the message sent by this function; otherwise, it wont.

Note:

This function waits until the receiving window completes processing a message before returning.

Note:

32-bit SU windows cannot communicate to 64-bit SU windows; However, 64-bit SU windows can communicate to 32-bit SU windows. For example, assume you have two SU windows open, SU2014 (32-bit) and SU2016 (64-bit). Calling send_user_message from the SU2014 window to the SU2016 window, will not succeed in the SU2016 window receiving the message. However, if you call send_user_message from the SU2016 window to the SU2014 window, the message will succeed in being received by the SU2014 window.

Send information to another window.

Examples:

# Open two or more SketchUp windows and paste the following, except the last
# line, into the Ruby consoles of each SketchUp window.
class MyTool

  # Our unique communication id
  PORT = 123

  def communicate_to_others(text)
    others = AMS::Sketchup.get_other_main_windows
    others.each { |handle|
      AMS::Sketchup.send_user_message(handle, PORT, text.to_s)
    }
  end

  def swo_on_user_message(sender, id, data)
    # Don't bother processing the message if ID is not ours.
    return if (id != PORT)
    # Process the message.
    p data
  end

end # class MyTool

my_tool = MyTool.new
# Register our class with SketchUp window observers.
AMS::Sketchup.add_observer(my_tool)

# Paste the following into one of the SU windows. Ensure that Ruby
# consoles are still open in other SU windows.
# As a result of calling the command below, all other SU windows should
# end-up having a hello message displayed in their Ruby consoles.
my_tool.communicate_to_others("Hello! I'm sent from a SketchUp window with a process id of #{Process.pid}")

Raises:

  • (TypeError)

    if given handle to a window is not valid.

  • (RangeError)

    if given ID is not within a range of 0 and 4095.

  • (TypeError)

    if given user-data or sub-user-data type is not supported.

Since:

  • 3.1.0


592
593
# File 'Documentation/ams/sketchup.rb', line 592

def send_user_message(receiver_handle, id, user_data)
end

.set_caption(caption) ⇒ Boolean

Set main window title text.

Since:

  • 2.0.0


458
459
# File 'Documentation/ams/sketchup.rb', line 458

def set_caption(caption)
end

.set_menu_bar(state) ⇒ Boolean

Set/Remove menu bar.

Since:

  • 2.0.0


134
135
# File 'Documentation/ams/sketchup.rb', line 134

def set_menu_bar(state)
end

.set_viewport_border(state) ⇒ Boolean

Set/Remove viewport border, a thin edge surrounding the view.

Since:

  • 2.0.0


145
146
# File 'Documentation/ams/sketchup.rb', line 145

def set_viewport_border(state)
end

.show_dialogs(state) ⇒ Fixnum

Note:

Ignored dialogs won't be included in this operation.

Show/hide all dialogs and trays.

Since:

  • 2.0.0


277
278
# File 'Documentation/ams/sketchup.rb', line 277

def show_dialogs(state)
end

.show_scenes_bar(state, refresh = true) ⇒ Boolean

Show/hide scenes bar.

Since:

  • 2.0.0


169
170
# File 'Documentation/ams/sketchup.rb', line 169

def show_scenes_bar(state, refresh = true)
end

.show_status_bar(state, refresh = true) ⇒ Boolean

Show/hide status bar.

Since:

  • 2.0.0


157
158
# File 'Documentation/ams/sketchup.rb', line 157

def show_status_bar(state, refresh = true)
end

.show_toolbar_container(bar, state, refresh = true) ⇒ Boolean

Show/hide toolbar container(s).

Since:

  • 2.0.0


208
209
# File 'Documentation/ams/sketchup.rb', line 208

def show_toolbar_container(bar, state, refresh = true)
end

.show_toolbars(state) ⇒ Fixnum

Show/hide all floating toolbars.

Since:

  • 2.0.0


316
317
# File 'Documentation/ams/sketchup.rb', line 316

def show_toolbars(state)
end

.show_trays(state) ⇒ Fixnum

Show/hide all trays.

Since:

  • 3.5.0


304
305
# File 'Documentation/ams/sketchup.rb', line 304

def show_trays(state)
end

.switch_full_screen(state, reset_mode = 2, set_mode = 1) ⇒ Boolean

Switch main window full screen.

Since:

  • 2.0.0


86
87
# File 'Documentation/ams/sketchup.rb', line 86

def switch_full_screen(state, reset_mode = 2, set_mode = 1)
end

.threaded_messagebox(caption, text, type = 0x00002030, owner_handle = nil) {|result| ... } ⇒ Fixnum?

Note:

Any errors occurring in the threaded block will be ignored.

Display a messagebox on a separate thread.

Examples:

Process while loop until a messagebox is closed.

caption = 'Decision'
text = 'Press OK to finish.'
done = false
thread_id = AMS::Sketchup.threaded_messagebox(caption, text) { |result|
  done = true
}
if thread_id
  while (!done)
    # Do something
  end
  puts 'Done'

  # You can also close the messagebox manually, in case you
  # finish doing something before the messagebox is closed.
  hwnd = AMS::Sketchup.find_window_by_caption(caption)
  AMS::Window.close(hwnd) if hwnd
end

Yields:

  • Triggered when the messagebox is closed.

Yield Parameters:

  • result (Fixnum)

    Message result

See Also:

Since:

  • 3.5.0


625
626
# File 'Documentation/ams/sketchup.rb', line 625

def threaded_messagebox(caption, text, type = 0x00002030, owner_handle = nil)
end