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

    Cursor snapping to a nearby point...

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 2 Posters 362 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.
    • A Offline
      ArchToBe
      last edited by

      Hi folks,

      Sketchup 7.1.4871
      Vista SP1, 32-bit

      I'm experimenting with capturing mouse coordinate input via tool class event handling. I'm using the "simple_tool.rb" script as a guide. Here's my little test script...


      class Clicktest

      Initialize the input point upon start

      def activate
      @pt1 = Sketchup::InputPoint.new
      end

      Respond to left-clicks in the design window

      def onLButtonDown flags, x, y, view
      @pt1.pick view, x, y
      @pos1 = @pt1.position
      str = "%.2f, %.2f, %.2f" % [@pos1.x, @pos1.y, @pos1.z]
      puts "pt1: " + str
      end
      end

      Create the Command object

      simple_cmd = UI::Command.new("ClickTest") {
      Sketchup.active_model.select_tool Clicktest.new
      }

      Add the Command to the Tools menu

      tool_menu = UI.menu "Tools"
      tool_menu.add_separator
      tool_menu.add_item simple_cmd

      When I select this tool and move the cursor towards a vertex, it appears to be selecting the vertex once the cursor gets sufficiently close to it, but it's not visually indicating that it's doing so. It doesn't behave the way Sketchup does when Sketchup is used manually - e.g. Sketchup uses tooltips and coloring to cue the user that a point close-to-but-not-immediately-underneath the cursor is about to be selected if the mouse is clicked. I think maybe this is called "snapping"?

      Is there a way that I can make this behavior more visually apparent to the user of the tool?

      Thanks!

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        In the draw event of your tool you must call @pt.draw.

        (You can wrap you code in [code] tags to preserve formatting and readability when posting.)

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • A Offline
          ArchToBe
          last edited by

          ThomThom,

          Thank you for your quick reply!

          In the draw event of your tool you must call @pt.draw. <<

          OK. But do you know of any reference materials that I could study to shed a little more light on this subject? I've looked around at the example files, and "linetool.rb" has a draw method - but it raises more questions than it answers.

          I'll do my homework, but it would be nice if there was some sort of documentation for this. I must be missing something somewhere.

          Thanks again!

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            You have the API docs: http://code.google.com/apis/sketchup/docs/ourdoc/tool.html

            Another point I forgot to mention was that you also need to invalidate the view to make it draw.

            The concept is:
            Whatever you want your tool to display in the viewport is added to the draw method of your tool. Here you use view.draw* methods for instance.
            But in order to trigger the draw method the view needs to be invalidated. ( view.invalidate) That will refresh the SU viewport and call your draw method.

            So in your mouse click event where you pick things, when you have new data to display you call view.invalidate which then leads to the draw method to be called and from there you draw whatever you want, in your case you want to draw @pt if it has anything to display ( @pt.draw if @pt.display?)

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • A Offline
              ArchToBe
              last edited by

              ThomThom,

              Again, thanks for your speedy and gracious response.

              You've provided some good information. Time permitting, I'll work on this this weekend and hopefully come to a better understanding.

              Take care!

              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