sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Detect User Access to Clipboard

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 4 Posters 978 Views 4 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.
    • K Offline
      kwalkerman
      last edited by

      Hi,

      Is there any way within Sketchup to detect when the user has accessed the clip-board through CTRL-V or a paste event? I am trying to detect when a user may have copied and pasted text from another application into Sketchup. I'd like to be able to use a ruby script read the text and potentially do something with it.

      Thanks,

      --
      Karen

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Not that I know - there are some undocumented send_actions for copy, paste etc but not to detect clipboard changes...
        You could perhaps use an AutoHotKey scripted tool to do the detection for you [perhaps launch the .ahk from Sketchup when the tool starts...]...
        You would set up a SUp UI timer to page a folder regularly and if a particular temp file appeared in it then use its contents to get the text [erasing the file immediately afterwards].
        Meanwhile AutoHoyKeys could detect if the clipboard changed and it contained text, and if so it'd write it into this named temp file ?
        I assume you'll use the text as the 'text' within some Text element ?
        πŸ˜•
        http://www.autohotkey.com/docs/misc/Clipboard.htm

        TIG

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          If it's the 3DTextTool, the entities of the component definition contain edges (a lot of them that make up the 3D letters!)

          But if it's only 1 line of text, the definition.name will be that first line.
          After the component move (the user places the 3DText component instance,) the active_model.selection will contain 1 item, the component instance, so:
          firstline = Sketchup.active_model.selection[0].definition.name

          The undo log gets these lines when 3Dtext is used:
          %(#800080)[Tool(3DTextTool) Start(3D Text)Commit(10) Tool(3DTextTool) Start(Component)Commit(11) Tool(MoveTool) Tool(MoveTool) Tool(MoveTool)]

          So you may be able to use a ToolsObserver object to detect use of the 3DtextTool.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            And BTW... we cannot cut and paste text directly into a model, nor can we drag and drop text into a model. (Look like there's no drag and drop handler for this.)

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              If it's the "Callout" TextTool, these are the Undo log lines:
              %(#8000BF)[Tool(TextTool) Start(Text)Commit(21)]

              You CAN get the text of a Sketchup::Text object, using it's text() getter instance method.

              But.. after placing the text, and pasting in from the clipboard, the TextTool is still active, but the selection is empty!

              So you would either, need to again track tool usage with a custom ToolsObserver, and / or track Sketchup::Text object additions to the active_entities context, using an EntitiesObserver via it's onElementAdded() callback.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @kwalkerman said:

                I'd like to be able to use a ruby script read the text and potentially do something with it.

                Now... IF you want to do this within your OWN custom Tool class, you should be able to detect CRTL+V in the onKeyUp and onKeyDown callbacks.

                You also, can detect if the user has put text into the VCB via your tool's onUserText() callback. (Should not matter if pasted or typed, but you could have set a boolean "paste_active" flag in the onKeyUp callback, and then use the VCB text accordingly.)

                If your using a UI::Inputbox, I doubt that a tool's onKey... callbacks will trap any keys.

                Using a UI::WebDialog, however, you maybe be able to trap certain keys in the Javascript.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • K Offline
                  kwalkerman
                  last edited by

                  Thanks. The autohotkey option gets me the closest. Now I just need to find out if I can use AHK to detect all paste events, not just ctrl-v paste events...

                  I am actually using the pasted text to create a ruby object unrelated and unconnected to a Sketchup Entity. I want the user to be able to simply paste whatever is on the clipboard into Sketchup, have a ruby script run and if the clipboard contains parsable text, I can create my ruby object. Another simpler, but less elegant way to do it is to have a large text field in a web dialog that the user can paste text to, and then run a script on that text.

                  --
                  Karen

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @kwalkerman said:

                    I want the user to be able to simply paste whatever is on the clipboard into Sketchup, ...

                    Karen, we cannot do this. The CTRL+V only works for copying groups, components, or the selection.

                    It only works for text, when a textbox control is active, such as in the VCB, the TextTool onscreen edit control, within the 3DTextTool's dialog, in the RubyConsole's inputbox, or any other textbox of a inputbox, or webdialog.

                    But you cannot just paste text "into Sketchup" such as when the SelectionTool is active (because CTRL is used to append to the selection.) Likewise, when any other tool is active and not expecting textinput.

                    You can tell by looking at the Edit menu, and see that the Paste item is greyed out (and CTRL+V is defeated.)

                    Edit: looks like the VCB does not accept text pastes.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      driven
                      last edited by

                      Hi,

                      I have an Applescript that opens RC then /copy/pastes/runs, it could easily include additional instructions. eg. open/join an existing ruby first.
                      I had one that also closed RC again, but I don't need that.

                      I can launch from inside SU or from separate menu-bar item that will open SU if it's closed.

                      Obviously mines a mac-hack, can you do that on a PC?

                      My experiments showed RC as the only reliable way in unless you paste/write to file and have 'system' request Sketchup to load it. Permissions can be tricky.

                      A WebDialog would avoid opening RC, but would need to be open itself first.

                      john

                      learn from the mistakes of others, you may not live long enough to make them all yourself...

                      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