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

    [Q] on mouse over component - boundingbox lightup

    Scheduled Pinned Locked Moved Plugins
    5 Posts 2 Posters 369 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.
    • R Offline
      rvs1977
      last edited by

      Greetings out there... β˜€

      I'm trying to make a snippet where a component's bounding box lights up, when the mouse is pointing at the object. I have looked around for a while at different classes, for instance the oberserver class and the UI class - pickhelper, but nothing seems to do the job.

      Can anyone tell me in which direction to look, or even better show me a rubyexample I can look in?

      thx in advance ❗

      -Rasmus


      Get a Ruby

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        The way I would do it is to make a tool. Then use the pickhelper class to track what the mouse is hovering over. THen anytime it hovers over a component, add the component to the selection set. When the cursor is no longer over the component, clear the selection set.

        This obviously has the limitation of clearing the selection set, which might not be idea for your plugin's needs. So instead of actually adding it to the selection set, instead you could use the draw method to highlight the bounding box.

        This is a fun exercise. I'll see if I can do a quick sample script.

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          Here is a simple example of making a tool that automatically adds a component instance to the selection set and clears the selection set if the cursor is not hovering over a component. Biggest downfalls of this code probably are that everytime the mouse moves, it either re-adds a component to the selection - even if it already in it! Or it clears the selection set, even if it is already clear. Ideally you would do something to track from mouse movement to mouse movement if the pickhelper has changed (instead of just adding and clearing the selection blindly).

          Also as I noted before, this clears the users selection set when the tool is activated, and it clears it repeatedly throughoutt he script, which generally is not a good idea. But in some scripts, it is exactly what you want.

          ` class Clf_highlight_bb

          def activate
          Sketchup.active_model.selection.clear
          @@ph= Sketchup.active_model.active_view.pick_helper
          end #activate

          def onMouseMove(flags, x, y, view)
          @@ph.do_pick x,y
          best = @@ph.best_picked
          if best.is_a? Sketchup::ComponentInstance
          Sketchup.active_model.selection.add best
          else
          Sketchup.active_model.selection.clear
          end
          end #onMouseMove

          end #class

          Sketchup.active_model.select_tool( Clf_highlight_bb.new )`

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            And here's a quick example of how to do it using the draw method in the tool. This does not mess with the selectio set at all. So if you want the user to be able to actualy select the object, you will need to add an onLClick method that adds the highlighted object to the selection set.

            Again, this code is not very optimized. It is calling the draw method (by calling view.invalidate!) each pixel that the mouse moves. You would be wise to make sure it only calls the draw method when it needs to.

            ` class Clf_highlight_bb

            def activate
            Sketchup.active_model.selection.clear
            @@ph= Sketchup.active_model.active_view.pick_helper
            @@best = []
            end #activate

            def onMouseMove(flags, x, y, view)
            @@ph.do_pick x,y
            @@best = @@ph.best_picked
            view.invalidate
            end #onMouseMove

            def draw(view)
            if @@best
            view.drawing_color = "red"
            bb = @@best.bounds
            pts = [bb.corner(0), bb.corner(1), bb.corner(2), bb.corner(3), bb.corner(4), bb.corner(5), bb.corner(6), bb.corner(7), bb.corner(0), bb.corner(2), bb.corner(1), bb.corner(3), bb.corner(4), bb.corner(6), bb.corner(5), bb.corner(7), bb.corner(0), bb.corner(4), bb.corner(1), bb.corner(5), bb.corner(2), bb.corner(6), bb.corner(3), bb.corner(7)]
            view.draw GL_LINES, pts
            end
            end

            end #class

            Sketchup.active_model.select_tool( Clf_highlight_bb.new )`

            Hope these examples help figure it out,

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • R Offline
              rvs1977
              last edited by

              Hi Chris

              Thank you so much!

              This is exactly what I was looking for. Once again this forum has helped me out! β˜€
              I'm trying to make a wall tool, and have an idea that this will be very usefull.

              -Rasmus


              Get a Ruby

              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