sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    [HowTo] Make SendKeys (WIN32OLE) works "immediately" ?

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 848 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      MarcioAB
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • W Offline
        wikii
        last edited by

        Pause the script a little moment to allow SU responds to the command of "close components".

        1 Reply Last reply Reply Quote 0
        • M Offline
          MarcioAB
          last edited by

          😳 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
          
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement