Hello, in the sketchup ruby API, can I use the ruby code to simulate a mouse click on the sub-menu in menu?
thank you very much!
This canât be done in Ruby alone. Maybe it can be done with OS specific libraries in other languages but I donât think it is a good idea. Menu items can be moved or renamed and their names are language specific. What items are available, and thus their indices, also heavily depends on what is selected and has several combinations.
Rather than trying to target a part of the GUI Iâd suggest to instead re-create the underlying action in Ruby.
Such as âFile - Open - choose .skp - saveâ. Instead of using code
Sketchup.open_file(skp)
Sketchup.active_model.save
can Ruby simulate this:
** access to** the menu âFileâ, then move to âOpenâ -> âChoose .skpâ -> click Open -> etc âŚ
Just for example, maybe he wants to slick different menu, but I think there are the same thing. Thx
I know how to do this on MS Windows âŚ
Search the Ruby API category on âWin32OLE SendKeysâ
Here is one post of mine ⌠How to set API Export IFC Options?
Your code works in my su, and i understand how to send key to su.
But when i assigned shortcut Ctrl Alt Shift T
to Thea Render/Create extendal model/proxy
, i canât use this fun to change anything.
require 'win32ole'
def test()
shell = WIN32OLE::new("WScript.Shell")
shell.SendKeys "^+%(T)"
end
# nothing happened...
I look up in SendKeys Method and i find that Ctrl Alt Shift T
-> â^+%(T)â, am i right?
Then i write this in su Ruby Panel:
shell = WIN32OLE::new("WScript.Shell")
shell.SendKeys "^(O)"
shell.SendKeys "^(N)"
Since Ctrl O
is to open select .skp window, etcâŚ, but nothing happens. Im confused:
Did i code wrong, or i canât send shortkey to su, or something else?
But thank you anyway !!!
You cannot test SendKeys from the Ruby Console window because the console window will receive the keys instead of the SketchUp application window.
Yes. (I think T should work the same as t.)
Try this âŚ
module LTC
module TheaShortcut
extend self
require 'win32ole'
def test()
puts "In method 'test', sending keys CTRL+ALT+SHIFT+T ..."
shell = WIN32OLE::new("WScript.Shell")
shell.SendKeys "^+%(t)"
end
UI.add_context_menu_handler {|popup|
popup.add_item("Test Thea Shortcut") { test() }
}
end
end
Then use the right-click context menu item to test from the main SketchUp window.