[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 endThe 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement