Module: AMS::Sketchup
- Defined in:
- sketchup.rb
Class Method Summary (collapse)
-
+ (Boolean) activate
(also: bring_to_top)
Set main window active.
-
+ (Boolean) add_observer(object)
Add object to the observers list.
-
+ (void) close
Close current SketchUp application.
-
+ (Fixnum) close_dialogs
Close all dialogs.
-
+ (Fixnum) close_toolbars
Close all floating toolbars.
-
+ (Fixnum?) find_window_by_caption(caption)
Find a handle to the window with the specified caption.
-
+ (Array<Fixnum>) get_active_dialogs
Get all used pop-up windows of the current SketchUp application.
-
+ (Array<Fixnum>) get_active_toolbars
Get all used floating toolbars.
-
+ (String) get_caption
Get main window title text.
-
+ (Array<Fixnum>) get_dialogs
Get all pop-up windows of the current SketchUp application.
-
+ (String) get_executable_path
Get full path to the current SketchUp executable.
-
+ (Fixnum) get_main_window
Get handle to the main window of the current SketchUp application.
-
+ (Fixnum) get_menu_bar
Get handle to the menu bar of the main window.
-
+ (Fixnum) get_module_handle
Get module handle to the current SketchUp application.
-
+ (Fixnum) get_process_id
Get process id of the current SketchUp application.
-
+ (String) get_registry_path
Get registry path of the current SketchUp application.
-
+ (Fixnum) get_scenes_bar
Get handle to the scenes bar of the main window.
-
+ (Fixnum) get_status_bar
Get handle to the status bar of the main window.
-
+ (Fixnum) get_thread_id
Get thread id of the current SketchUp application.
-
+ (Array<Fixnum>) get_toolbar_containers
Get handle to the four toolbar containers of the main window.
-
+ (Array<Fixnum>) get_toolbars
Get all floating toolbars of the current SketchUp application.
-
+ (Fixnum) get_viewport
Get handle to the view window of the main window.
-
+ (Array<Fixnum>) get_viewport_center
Get viewport center in screen coordinates.
-
+ (Array<Fixnum>) get_viewport_origin
Get upper-left corner of the view window in screen coordinates.
-
+ (Array<Fixnum>) get_viewport_rect
Get upper-left and lower-right corners of the view window in screen coordinates, relatives to the upper-left corner of the screen.
-
+ (Array<Fixnum>) get_viewport_size
Get width and height of the view window.
-
+ (Array<Fixnum>) get_visible_dialogs
Get all visible pop-up windows of the current SketchUp application.
-
+ (Array<Fixnum>) get_visible_toolbars
Get all visible floating toolbars of the current SketchUp application.
-
+ (Boolean) ignore_dialog(handle)
Elude dialog from the Sketchup.show_dialogs and Sketchup.close_dialogs operations.
-
+ (Boolean) include_dialog(handle)
Include dialog in the Sketchup.show_dialogs and Sketchup.close_dialogs operations.
-
+ (Boolean) is_32bit?
Determine whether current SketchUp application is 32bit.
-
+ (Boolean) is_64bit?
Determine whether current SketchUp application is 64bit.
-
+ (Boolean) is_active?
Determine whether the current active window belongs to the current SketchUp application.
-
+ (Boolean) is_full_screen?
Determine whether main window is full screen.
-
+ (Boolean) is_main_window_active?
Determine whether SketchUp main window is active.
-
+ (Boolean) is_maximized?
Determine whether main window is maximized.
-
+ (Boolean) is_menu_bar_set?
Determine whether menu bar is set.
-
+ (Boolean) is_minimized?
Determine whether main window is minimized.
-
+ (Boolean) is_restored?
Determine whether main window is restored.
-
+ (Boolean) is_scenes_bar_empty?
Determine whether scenes bar is empty.
-
+ (Boolean) is_scenes_bar_filled?
Determine whether scenes bar is filled.
-
+ (Boolean) is_scenes_bar_visible?
Determine whether scenes bar is visible.
-
+ (Boolean) is_status_bar_visible?
Determine whether status bar is visible.
-
+ (Boolean) is_toolbar_container_empty?(bar)
Determine whether toolbar container(s) is/are empty.
-
+ (Boolean) is_toolbar_container_filled?(bar)
Determine whether toolbar container(s) is/are filled.
-
+ (Boolean) is_toolbar_container_visible?(bar)
Determine whether toolbar container(s) is/are visible.
-
+ (Boolean) is_viewport_border_set?
Determine whether viewport border is set.
-
+ (Boolean) maximize
Set main window maximized.
-
+ (Boolean) minimize
Set main window minimized.
-
+ (void) refresh
Refresh current SketchUp application.
-
+ (Boolean) remove_observer(object)
Remove object from the observers list.
-
+ (Boolean) restore
Set main window to normal placement.
-
+ (Boolean) set_caption(caption)
Set main window title text.
-
+ (Boolean) set_menu_bar(state)
Set/Remove menu bar.
-
+ (Boolean) set_viewport_border(state)
Set/Remove viewport border, a thin edge surrounding the view.
-
+ (Fixnum) show_dialogs(state)
Show/Hide all dialogs.
-
+ (Boolean) show_scenes_bar(state, refresh = true)
Show/Hide scenes bar.
-
+ (Boolean) show_status_bar(state, refresh = true)
Show/Hide status bar.
-
+ (Boolean) show_toolbar_container(bar, state, refresh = true)
Show/Hide toolbar container(s).
-
+ (Fixnum) show_toolbars(state)
Show/Hide all floating toolbars.
-
+ (Boolean) switch_full_screen(state, reset_mode = 2)
Set main window full screen.
Class Method Details
+ (Boolean) activate Also known as: bring_to_top
Set main window active.
190 191 192 |
# File 'sketchup.rb', line 190 def activate AMS::C.bring_window_to_top(AMS::C.get_main_window()) end |
+ (Boolean) add_observer(object)
An observer can be a class, module, or a class instance. Your observer will work as long as the callback methods are public.
Your observer is not supposed to contain every callback method from the observers list. You may include/elude those as you wish.
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, then 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 handy for
extensions that want more control over SketchUp.
Add object to the observers list.
704 705 706 |
# File 'sketchup.rb', line 704 def add_observer(object) AMS::C.add_observer(object) end |
+ (void) close
This behaves the same as clicking the 'X' button.
This method returns an undefined value.
Close current SketchUp application.
650 651 652 |
# File 'sketchup.rb', line 650 def close AMS::C.close_window(AMS::C.get_main_window()) end |
+ (Fixnum) close_dialogs
Ignored windows won't be included in this operation.
Close all dialogs.
475 476 477 478 479 480 481 482 483 484 485 |
# File 'sketchup.rb', line 475 def close_dialogs count = 0 (@dialogs + AMS::C.get_visible_dialogs()).each { |handle| next unless AMS::C.is_window?(handle) next if @dialogs_to_ignore.include?(handle) AMS::C.close_window(handle) count += 1 } @dialogs.clear count end |
+ (Fixnum) close_toolbars
Close all floating toolbars.
542 543 544 545 546 547 548 549 550 551 |
# File 'sketchup.rb', line 542 def count = 0 (@toolbars + AMS::C.()).each { |handle| next unless AMS::C.is_window?(handle) AMS::C.close_window(handle) count += 1 } @toolbars.clear count end |
+ (Fixnum?) find_window_by_caption(caption)
This function will irritate through the windows of the current SketchUp process only. All windows belong to a different process or a different SketchUp application will not be searched.
Find a handle to the window with the specified caption.
575 576 577 |
# File 'sketchup.rb', line 575 def find_window_by_caption(caption) AMS::C.find_window_by_caption(caption) end |
+ (Array<Fixnum>) get_active_dialogs
Ignored dialogs are included in the list.
Get all used pop-up windows of the current SketchUp application.
591 592 593 |
# File 'sketchup.rb', line 591 def get_active_dialogs (AMS::C.get_visible_dialogs() + @dialogs - @dialogs_to_ignore).uniq end |
+ (Array<Fixnum>) get_active_toolbars
Get all used floating toolbars.
613 614 615 |
# File 'sketchup.rb', line 613 def (AMS::C.() + @toolbars).uniq end |
+ (String) get_caption
Get main window title text.
627 628 629 |
# File 'sketchup.rb', line 627 def get_caption AMS::C.get_window_text(AMS::C.get_main_window()).unpack('C*').pack('U*') end |
+ (Array<Fixnum>) get_dialogs
Ignored dialogs are included in the list.
Get all pop-up windows of the current SketchUp application.
583 584 585 |
# File 'sketchup.rb', line 583 def get_dialogs AMS::C.get_dialogs() - @dialogs_to_ignore end |
+ (String) get_executable_path
Get full path to the current SketchUp executable.
39 40 41 42 43 |
# File 'sketchup.rb', line 39 def get_executable_path path = AMS::C.get_executable_path().unpack('C*').pack('U*') path.gsub!(/\\/, '/') path end |
+ (Fixnum) get_main_window
Get handle to the main window of the current SketchUp application.
77 78 79 |
# File 'sketchup.rb', line 77 def get_main_window AMS::C.get_main_window end |
+ (Fixnum) get_menu_bar
Get handle to the menu bar of the main window.
84 85 86 |
# File 'sketchup.rb', line 84 def AMS::C. end |
+ (Fixnum) get_module_handle
Get module handle to the current SketchUp application.
32 33 34 |
# File 'sketchup.rb', line 32 def get_module_handle AMS::C.get_module_handle end |
+ (Fixnum) get_process_id
Get process id of the current SketchUp application.
63 64 65 |
# File 'sketchup.rb', line 63 def get_process_id AMS::C.get_process_id end |
+ (String) get_registry_path
Get registry path of the current SketchUp application.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'sketchup.rb', line 48 def get_registry_path version = Sketchup.version.to_i case version when 5 "HKEY_CURRENT_USER/Software/Google/Google SketchUp5/" when 6..8 "HKEY_CURRENT_USER/Software/Google/SketchUp#{version}/" else "HKEY_CURRENT_USER/Software/SketchUp/SketchUp 20#{version}/" end end |
+ (Fixnum) get_scenes_bar
Get handle to the scenes bar of the main window.
105 106 107 |
# File 'sketchup.rb', line 105 def AMS::C. end |
+ (Fixnum) get_status_bar
Get handle to the status bar of the main window.
98 99 100 |
# File 'sketchup.rb', line 98 def AMS::C. end |
+ (Fixnum) get_thread_id
Get thread id of the current SketchUp application.
70 71 72 |
# File 'sketchup.rb', line 70 def get_thread_id AMS::C.get_thread_id end |
+ (Array<Fixnum>) get_toolbar_containers
Get handle to the four toolbar containers of the main window.
112 113 114 |
# File 'sketchup.rb', line 112 def AMS::C. end |
+ (Array<Fixnum>) get_toolbars
Get all floating toolbars of the current SketchUp application.
606 607 608 |
# File 'sketchup.rb', line 606 def AMS::C.() end |
+ (Fixnum) get_viewport
Get handle to the view window of the main window.
91 92 93 |
# File 'sketchup.rb', line 91 def AMS::C. end |
+ (Array<Fixnum>) get_viewport_center
Get viewport center in screen coordinates.
406 407 408 409 |
# File 'sketchup.rb', line 406 def r = AMS::C.() [((r[2] - r[0])*0.5).round, ((r[3] - r[1])*0.5).round] end |
+ (Array<Fixnum>) get_viewport_origin
Get upper-left corner of the view window in screen coordinates.
390 391 392 |
# File 'sketchup.rb', line 390 def AMS::C.()[0,2] end |
+ (Array<Fixnum>) get_viewport_rect
Get upper-left and lower-right corners of the view window in screen coordinates, relatives to the upper-left corner of the screen.
383 384 385 |
# File 'sketchup.rb', line 383 def AMS::C.() end |
+ (Array<Fixnum>) get_viewport_size
This is same as view.vp_width and view.vp_height.
Get width and height of the view window.
398 399 400 401 |
# File 'sketchup.rb', line 398 def r = AMS::C.() [ r[2] - r[0], r[3] - r[1] ] end |
+ (Array<Fixnum>) get_visible_dialogs
Ignored dialogs are included in the list.
Get all visible pop-up windows of the current SketchUp application.
599 600 601 |
# File 'sketchup.rb', line 599 def get_visible_dialogs AMS::C.get_visible_dialogs() - @dialogs_to_ignore end |
+ (Array<Fixnum>) get_visible_toolbars
Get all visible floating toolbars of the current SketchUp application.
620 621 622 |
# File 'sketchup.rb', line 620 def AMS::C.() end |
+ (Boolean) ignore_dialog(handle)
Elude dialog from the show_dialogs and close_dialogs operations.
501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'sketchup.rb', line 501 def ignore_dialog(handle) # Verify given handle is not already in the ignore list. return false if @dialogs_to_ignore.include?(handle) # Verify given handle is a window. return false unless AMS::C.is_window?(handle) # Verify given handle is part of the current SketchUp process. return false if AMS::C.get_window_process_id(handle) != AMS::C.get_process_id() # Verify given handle is a pop-up window. return false if AMS::C.get_window_class_name(handle) != '#32770' # Add handle to the ignore list if it passed all the tests. @dialogs_to_ignore << handle true end |
+ (Boolean) include_dialog(handle)
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.
493 494 495 |
# File 'sketchup.rb', line 493 def include_dialog(handle) @dialogs_to_ignore.delete(handle) ? true : false end |
+ (Boolean) is_32bit?
Determine whether current SketchUp application is 32bit.
18 19 20 |
# File 'sketchup.rb', line 18 def is_32bit? !@is_64bit end |
+ (Boolean) is_64bit?
Determine whether current SketchUp application is 64bit.
25 26 27 |
# File 'sketchup.rb', line 25 def is_64bit? @is_64bit end |
+ (Boolean) is_active?
Determine whether the current active window belongs to the current SketchUp application.
564 565 566 567 |
# File 'sketchup.rb', line 564 def is_active? handle = AMS::C.get_active_window() AMS::C.get_window_process_id(handle) == AMS::C.get_process_id() end |
+ (Boolean) is_full_screen?
Determine whether main window is full screen.
129 130 131 |
# File 'sketchup.rb', line 129 def is_full_screen? AMS::C.is_main_window_full_screen? end |
+ (Boolean) is_main_window_active?
Determine whether SketchUp main window is active.
556 557 558 |
# File 'sketchup.rb', line 556 def is_main_window_active? AMS::C.get_active_window() == AMS::C.get_main_window() end |
+ (Boolean) is_maximized?
Determine whether main window is maximized.
146 147 148 149 |
# File 'sketchup.rb', line 146 def is_maximized? return false if AMS::C.is_main_window_full_screen? AMS::C.is_window_maximized?(AMS::C.get_main_window()) end |
+ (Boolean) is_menu_bar_set?
Determine whether menu bar is set.
207 208 209 |
# File 'sketchup.rb', line 207 def AMS::C. end |
+ (Boolean) is_minimized?
Determine whether main window is minimized.
163 164 165 |
# File 'sketchup.rb', line 163 def is_minimized? AMS::C.is_window_minimized?(AMS::C.get_main_window()) end |
+ (Boolean) is_restored?
Determine whether main window is restored.
180 181 182 183 184 185 |
# File 'sketchup.rb', line 180 def is_restored? return false if AMS::C.is_main_window_full_screen? return false if AMS::C.is_window_minimized?(AMS::C.get_main_window()) return false if AMS::C.is_window_maximized?(AMS::C.get_main_window()) true end |
+ (Boolean) is_scenes_bar_empty?
Determine whether scenes bar is empty. Scenes bar is empty if there are no pages in the model.
271 272 273 |
# File 'sketchup.rb', line 271 def AMS::C.() end |
+ (Boolean) is_scenes_bar_filled?
Determine whether scenes bar is filled. Scenes bar is filled if there is at least one page in the model.
263 264 265 |
# File 'sketchup.rb', line 263 def AMS::C.() end |
+ (Boolean) is_scenes_bar_visible?
Determine whether scenes bar is visible.
255 256 257 |
# File 'sketchup.rb', line 255 def AMS::C. end |
+ (Boolean) is_status_bar_visible?
Determine whether status bar is visible.
238 239 240 |
# File 'sketchup.rb', line 238 def AMS::C. end |
+ (Boolean) is_toolbar_container_empty?(bar)
Determine whether toolbar container(s) is/are empty.
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'sketchup.rb', line 361 def () = AMS.clamp(.to_i, 1, 6) case when 1..4 AMS::C.() when 5 for i in 1..4 return true if AMS::C.(i) end false else for i in 1..4 return false unless AMS::C.(i) end true end end |
+ (Boolean) is_toolbar_container_filled?(bar)
Determine whether toolbar container(s) is/are filled.
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'sketchup.rb', line 338 def () = AMS.clamp(.to_i, 1, 6) case when 1..4 AMS::C.() when 5 for i in 1..4 return true if AMS::C.(i) end false else for i in 1..4 return false unless AMS::C.(i) end true end end |
+ (Boolean) is_toolbar_container_visible?(bar)
Determine whether toolbar container(s) is/are visible.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'sketchup.rb', line 309 def () = AMS.clamp(.to_i, 1, 7) case when 1..4 AMS::C.() when 5 for i in 1..4 return true if AMS::C.(i) end false when 6 for i in 1..4 return false unless AMS::C.(i) end true else count = 0 for i in 1..4 return false if AMS::C.(i) && !AMS::C.(i) end true end end |
+ (Boolean) is_viewport_border_set?
Determine whether viewport border is set.
222 223 224 |
# File 'sketchup.rb', line 222 def AMS::C. end |
+ (Boolean) maximize
Set main window maximized.
136 137 138 139 140 141 |
# File 'sketchup.rb', line 136 def maximize return false if is_maximized? AMS::C.set_main_window_full_screen(false, 1) AMS::C.show_window(AMS::C.get_main_window(), 3) true end |
+ (Boolean) minimize
Set main window minimized.
154 155 156 157 158 |
# File 'sketchup.rb', line 154 def minimize return false if is_minimized? AMS::C.show_window(AMS::C.get_main_window(), 3) true end |
+ (void) refresh
This method returns an undefined value.
Refresh current SketchUp application.
642 643 644 |
# File 'sketchup.rb', line 642 def refresh AMS::C.refresh_window(AMS::C.get_main_window()) end |
+ (Boolean) remove_observer(object)
Remove object from the observers list.
712 713 714 |
# File 'sketchup.rb', line 712 def remove_observer(object) AMS::C.remove_observer(object) end |
+ (Boolean) restore
Set main window to normal placement.
170 171 172 173 174 175 |
# File 'sketchup.rb', line 170 def restore return false if is_restored? AMS::C.set_main_window_full_screen(false, 0) AMS::C.show_window(AMS::C.get_main_window(), 9) true end |
+ (Boolean) set_caption(caption)
Set main window title text.
635 636 637 |
# File 'sketchup.rb', line 635 def set_caption(caption) AMS::C.set_window_text(AMS::C.get_main_window(), caption.to_s.unpack('U*').pack('C*')) end |
+ (Boolean) set_menu_bar(state)
Set/Remove menu bar.
200 201 202 |
# File 'sketchup.rb', line 200 def (state) AMS::C.(state) end |
+ (Boolean) set_viewport_border(state)
Set/Remove viewport border, a thin edge surrounding the view.
215 216 217 |
# File 'sketchup.rb', line 215 def (state) AMS::C.(state) end |
+ (Fixnum) show_dialogs(state)
Ignored windows won't be included in this operation.
Show/Hide all dialogs.
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'sketchup.rb', line 416 def show_dialogs(state) count = 0 su_dialogs = [] if state @dialogs.each { |handle| next unless AMS::C.is_window?(handle) next if @dialogs_to_ignore.include?(handle) || AMS::C.is_window_visible?(handle) caption = AMS::Window.get_text(handle) if @su_controlled_dialogs.include?(caption) su_dialogs << handle else AMS::C.show_window(handle, 8) # SW_SHOWNA end count += 1 } @dialogs.clear unless su_dialogs.empty? Sketchup.send_action(21926) UI.start_timer(0.1, false){ su_dialogs.each { |handle| next unless AMS::C.is_window?(handle) next if AMS::C.is_window_visible?(handle) Sketchup.send_action(21926) break } } end else visible_dialogs = AMS::C.get_visible_dialogs() @dialogs.concat visible_dialogs visible_dialogs.each { |handle| next if @dialogs_to_ignore.include?(handle) caption = AMS::Window.get_text(handle) if @su_controlled_dialogs.include?(caption) su_dialogs << handle else AMS::C.show_window(handle, 0) # SW_HIDE end count += 1 } unless su_dialogs.empty? Sketchup.send_action(21926) UI.start_timer(0.1, false){ su_dialogs.each { |handle| next unless AMS::C.is_window?(handle) next unless AMS::C.is_window_visible?(handle) Sketchup.send_action(21926) break } } end end count end |
+ (Boolean) show_scenes_bar(state, refresh = true)
Show/Hide scenes bar.
247 248 249 250 |
# File 'sketchup.rb', line 247 def (state, refresh = true) return false if state && AMS::C.() AMS::C.(state, refresh) end |
+ (Boolean) show_status_bar(state, refresh = true)
Show/Hide status bar.
231 232 233 |
# File 'sketchup.rb', line 231 def (state, refresh = true) AMS::C.(state, refresh) end |
+ (Boolean) show_toolbar_container(bar, state, refresh = true)
Show/Hide toolbar container(s).
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'sketchup.rb', line 282 def (, state, refresh = true) = AMS.clamp(.to_i, 1, 6) case when 1..4 AMS::C.(, state, refresh) when 5 change = false for i in 1..4 if AMS::C.(i) change = true if AMS::C.(i, state, refresh) end end change else change = false for i in 1..4 change = true if AMS::C.(i, state, refresh) end change end end |
+ (Fixnum) show_toolbars(state)
Show/Hide all floating toolbars.
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'sketchup.rb', line 519 def (state) count = 0 if state @toolbars.each { |handle| next unless AMS::C.is_window?(handle) AMS::C.show_window(handle, 8) # SW_SHOWNA count += 1 } @toolbars.clear else = AMS::C.() @toolbars.concat .each { |handle| AMS::C.show_window(handle, 0) # SW_HIDE count += 1 } end count end |
+ (Boolean) switch_full_screen(state, reset_mode = 2)
Set main window full screen.
122 123 124 |
# File 'sketchup.rb', line 122 def switch_full_screen(state, reset_mode = 2) AMS::C.set_main_window_full_screen(state, reset_mode.to_i) end |