[HowTo] Make SendKeys (WIN32OLE) works "immediately" ?
-
I'm trying to follow this topic from TIG to be able to Open/Close Components but it is not working as I was expecting. SendKeys only sends the key after all code finish and not immediately, example:
Assume I have "x" as a shortcut to "Edit/Close Component", a child component Opened (Edit) and want to Close it. This is the code:
def test p Sketchup.active_model.active_path WIN32OLE.new("WScript.Shell").SendKeys("x") p Sketchup.active_model.active_path end
The first Active_path show
[#Sketchup::ComponentInstance:0x4a79290, #Sketchup::ComponentInstance:0x4a79278]but the 2nd Active_path (still) show
[#Sketchup::ComponentInstance:0x4a79290, #Sketchup::ComponentInstance:0x4a79278]Because ComponentInstance:0x4a79278 was Closed, it should show
[#Sketchup::ComponentInstance:0x4a79290]When the above code finish in fact the Active_path is on [#Sketchup::ComponentInstance:0x4a79290], but not ("immediately") during the code execution. It's like SendKeys kept "x" buffered and just release it when SketchUp assume control.
Am I missing something, Can SendKeys works immediately, or Is there a workaround ?
Thank you
Marcio -
Pause the script a little moment to allow SU responds to the command of "close components".
-
Just discovered I can Close components with "Sketchup.active_model.close_active"
Thank you, but even with sleep(5) and bring the window to focus ... no success to trigger "Edit Component" shortcut ("Y").
p Sketchup.active_model.active_path s=WIN32OLE.new("WScript.Shell") p s.AppActivate("SketchUp") sleep(5) p s.SendKeys("y") sleep(5) p Sketchup.active_model.active_path
Advertisement