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

How do I use linetool.rb script?

Scheduled Pinned Locked Moved Plugins
11 Posts 5 Posters 2.5k Views
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
    mgianzero
    last edited by 22 Apr 2010, 02:06

    I am interested in adding mouse (and cursor) info as part of my ruby script inputs. So I thought I'd study the linetool.rb to see how it works.

    But how do I use it? I know it's part of Examples that comes with Sketchup and can be activated with extensions (I think) but where do I select the tool and use it?

    What am I missing? I feel like I'm asking a really basic (dumb) question here.

    Marc

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 22 Apr 2010, 04:13

      Here is a MUCH more basic version of a tool. Essentially you just need to make a class, then activate your tool using the method Sketchup.active_model.select_tool(My_Tool.new). Pass an object of your class as shown. That is how you start your tool. Below is an entire example of a functioning tool. Open the ruby console when you run this tool and it will display things as you move the mouse.

      ` class My_Tool

      def activate
      puts "Been Activated"
      end

      def onMouseMove(flags, x, y, view)
      puts "onMouseMove: flags = " + flags.to_s
      puts " x = " + x.to_s
      puts " y = " + y.to_s
      puts " view = " + view.to_s
      end

      end

      Sketchup.active_model.select_tool(My_Tool.new)`

      There is also a thread where we talked a little bit about this here:

      http://forums.sketchucation.com/viewtopic.php?f=180&t=26039

      Read through that, it might be a little more helpful than just my quick example. Good luck, come back with more questions as needed πŸ˜„

      Chris

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

      1 Reply Last reply Reply Quote 0
      • M Offline
        mgianzero
        last edited by 23 Apr 2010, 00:59

        Thanks for jumping in to help me here Chris. However, I'm very new to Ruby and still confused. I copied your routine into my ruby file as a start. But I don't see how you use it?

        That is, for the Examples->Box script (box.rb), it was straight forward since it puts a menu item for Box under the Draw menu using the UI.menu command. Then you select it and enter the parameters.

        In your example (like the linetool.rb example that comes with Sketchup) I don't see how you "activate" it. What menu, tool palette, etc. do you select to get this script running? Or do I manually load it from the Ruby console? If so, how?

        I'd prefer to see a completed piece of code (just a little more fleshed out from your example) that makes this script a tool menu selection and tells me when it reads a mouse click or tells me the point position as an example. Could you show me such code?

        Marc

        1 Reply Last reply Reply Quote 0
        • M Offline
          mgianzero
          last edited by 23 Apr 2010, 05:12

          Well, if you play around with Sketchup enough, you can answer your own questions. I think I did it. I just put my Sketchup.active_model.select_tool() command with a UI.menu. Did I do this right?

          **UI.menu("Tool").add_item("my tool") {
          Sketchup.send_action "showRubyPanel:"
          Sketchup.active_model.select_tool(My_Tool.new)
          }

          class My_Tool
          def activate
          puts "My tool has been activated"
          end

          def deactivate(view)
          puts "My tool has been deactivated."
          view.invalidate if @drawn
          end

          def onMouseMove(flags, x, y, view)
          puts "onMouseMove: flags = " + flags.to_s
          puts " x = " + x.to_s
          puts " y = " + y.to_s
          puts " view = " + view.to_s
          end

          def onLButtonDown(flags, x, y, view)
          puts "left mouse button clicked."
          end

          def onLButtonUp(flags, x, y, view)
          puts "left mouse button released."
          end

          end #end of class My_Tool

          ~**

          1 Reply Last reply Reply Quote 0
          • C Offline
            Chris Fullmer
            last edited by 23 Apr 2010, 06:27

            Yeah, that looks about right. Generally the menu loading portion comes down at the end. But I guess if it works, I can't think of a reason why it would have to be at the end, as long as the script gets a chance to load before you try to call any of the methods defined below.

            So that is a very basic tool. Look around at the other methods of the tool class. Many are straightforward - just add them and they will do their thing (onmousemove fires each time the mouse moves, etc). But some are trickier. Just ask questions if something is not working or not making sense. Many of us are not programming gurus. SketchUp ruby is my first programming language.

            Chris

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

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 23 Apr 2010, 06:57

              @chris fullmer said:

              Generally the menu loading portion comes down at the end.

              I put mine at the beginning so it's immediately visible to anyone viewing the code where the UI entry points are.

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

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by 23 Apr 2010, 08:27

                The 'convention' is

                Usage Notes
                Require Code
                Main Code
                Menu Code

                but some 'renegades' πŸ˜‰ like to move things around - it doesn't really matter - best if Notes are at the start I think, and I can see the efficacy of having the menu immediately following that though...

                TIG

                1 Reply Last reply Reply Quote 0
                • M Offline
                  mgianzero
                  last edited by 23 Apr 2010, 13:10

                  Okay. Yes, I've programmed quite a bit in C++ and it would make more sense to define your classes first and then put the main code afterwards.

                  But how do I convert these x, y coordinates into something useful, like RGB (or true x,y,z) cartesian coordinates? I know is has something to do with the InputPoint method.

                  My next step would be to change the cursor to something different so the user knows he's got my tool. Isn't this an option most people like to have?

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 23 Apr 2010, 13:24

                    @mgianzero said:

                    But how do I convert these x, y coordinates into something useful, like RGB (or true x,y,z) cartesian coordinates? I know is has something to do with the InputPoint method.

                    Yes - you create in InputPoint object and call the .pick method with the x and y arguments given from the Tool's mouse events. After the pick you can extract the various data you want. For X,Y,Z use inputpoint.position.

                    Note that the InputPoint class uses the SU inference system. If you don't want infering you can use the PickHelper.

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

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      mgianzero
                      last edited by 24 Apr 2010, 02:57

                      @thomthom said:

                      @mgianzero said:

                      But how do I convert these x, y coordinates into something useful, like RGB (or true x,y,z) cartesian coordinates? I know is has something to do with the InputPoint method.

                      Yes - you create in InputPoint object and call the .pick method with the x and y arguments given from the Tool's mouse events. After the pick you can extract the various data you want. For X,Y,Z use inputpoint.position.

                      Thanks for the comments. But could you please show exactly what you mean by example? Perhaps using my code above and modify it.

                      Sorry but I find that I can follow these suggestions better when I have a piece of code I can work off of.

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        kyyu
                        last edited by 26 Apr 2010, 23:56

                        @mgianzero said:

                        @thomthom said:

                        @mgianzero said:

                        But how do I convert these x, y coordinates into something useful, like RGB (or true x,y,z) cartesian coordinates? I know is has something to do with the InputPoint method.

                        Yes - you create in InputPoint object and call the .pick method with the x and y arguments given from the Tool's mouse events. After the pick you can extract the various data you want. For X,Y,Z use inputpoint.position.

                        Thanks for the comments. But could you please show exactly what you mean by example? Perhaps using my code above and modify it.

                        Sorry but I find that I can follow these suggestions better when I have a piece of code I can work off of.

                        Hi Marc,

                        I have just started leaning ruby and not a programmer, so can't help with programming info. But look at Plugins\Utilities\utilitiestools.rb as an example. You have to activate the extension "Utilites Tools". You use the tool from the Tools menu in sketchup => Tools/Utilities/"Query Tool". It displays cursor position in the bottom title space and the VCB.

                        Using that as an example, helped me to write a plugin. With a little cut and paste and trial/error. My plugin just rotates everything, that is initially selected, to be parallel with an axis. You select, two points to indicate a line. And the line provides the angles for the rotation.

                        -Kwok

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        1 / 1
                        • First post
                          1/11
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement