sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Making a SketchUp tool - incorporating the mouse & keyboard

    Scheduled Pinned Locked Moved Developers' Forum
    55 Posts 6 Posters 1.8k Views 6 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.
    • B Offline
      BTM
      last edited by

      ` model= Sketchup.active_model
      @ent= model.entities

      prompts = ["X", "Y", "Z"]
      defaults = [ 0.0.to_l, 0.0.to_l, 0.0.to_l]
      list = ["", "", ""]
      results = UI.inputbox prompts, defaults, list, "Input X, Y, Z."
      pt1= Geom::Point3d.new results
      pt2= [ 0, 0, 0]
      line = @ent.add_edges pt1, pt2`
      πŸ˜‰

      1 Reply Last reply Reply Quote 0
      • B Offline
        BTM
        last edited by

        That's strange. .to_i worked fine on my mac. πŸ˜•

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

          Hey!!!! Great job. I was really confused how on earth to get the inputbox to work in the default units! That did the trick though, setting it to 0.0.to_l. I really couldn't figure that out.

          So there you have it, 0.0.to_l makes the inputbox work in the default units. Thanks for posting the solution before I went crazy!

          Chris

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

          1 Reply Last reply Reply Quote 0
          • B Offline
            BTM
            last edited by

            @chris fullmer said:

            you might need to provide a way to make and place construction points.

            ` model = Sketchup.active_model
            @ent = model.entities

            prompts = ["X", "Y", "Z"]
            defaults = [ 0.0.to_l, 0.0.to_l, 0.0.to_l]
            list = ["", "", ""]
            results = UI.inputbox prompts, defaults, list, "Input X, Y, Z."
            pt1= Geom::Point3d.new results
            @ent.add_cpoint pt1`
            πŸ˜„

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

              Excellent πŸ˜„

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

              1 Reply Last reply Reply Quote 0
              • B Offline
                BTM
                last edited by

                ... Now I need to figure out where in the class to put that πŸ˜’ . I'm still not that fond of what defs do what exactly.

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

                  I think you'll probably put it in its own method.

                  If you want it to be the first thing run every time the user begins the script, then you can call that method at the bottom of the activate method.

                  And then call other methods from the onReturn method probably (though onLbuttonUp is common too). So it works like this, if you want your script to advance when the user hits enter, then call all YOUR methods from the onReturn method. It only gets triggered when the user hits enter/return. So only call your method from within onReturn and it will only get run once they hit enter. Here's an example of how it could flow

                  Your "add cpoint" method gets run from the activate method because that is run everytime the user starts the tool. So that will run your construction point right off the bat. Then the user should click on a vertex to specify that vertex as the center of operations. So you would have code in the onLbuttonUp method that yould trigger when they click the mouse. It should take the InputPoint and store it as some @centerPoint variable, assuming its a vertex they clicked on).

                  Once the cpoint is set and the centerpoint is selected, you could pop up a UI.inputbox asking what radius to use. When they hit enter, then you run a method that does all the calculation and drawing/transforming.

                  The way I described it there did not require the user to hit enter, so all that would be run from the onLButtonUp method then.

                  Seriously a tool with the mouse, and with transformations. Nearly as hard as it gets, but do-able. Good luck!

                  Chris

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

                  1 Reply Last reply Reply Quote 0
                  • B Offline
                    BTM
                    last edited by

                    One problem i'm having is not knowing what to enter in the grayed in area. I thought that Pinchmover, the name of the class, would work, but it doesn't. What does?
                    I put in a bunch of variables at the start, just incase I'll need them, so I won't forget what they are.

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

                      Sketchup.active_model.select_tool Pinchmover.new

                      And you will also need to move that to the bottom of the script. You can't instantiate the class until after it has been defined. Just put all your menu work at the bottom of the 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

                        Just the name of the class doesn't work, because with "tools" you are making special classes that Sketchup watches. So you have to tell sketchup to start your class as a tool.

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

                        1 Reply Last reply Reply Quote 0
                        • B Offline
                          BTM
                          last edited by

                          Okay πŸ‘
                          Man, I've got a LOT to learn πŸ˜†

                          1 Reply Last reply Reply Quote 0
                          • B Offline
                            BTM
                            last edited by

                            ` require "sketchup.rb"

                            class Pinchmover
                            
                            	def activate
                            	@model = Sketchup.active_model
                            	@ent = @model.entities
                            	@view = @model.active_view
                            	@slct = @model.selection
                            	@slct.clear
                            	end
                            
                            	def onLButtonUp(flags, x, y, view)
                            	ip = view.inputpoint x,y
                            	pt = ip.position
                            	pt2 = Geom::Point3d.new pt
                            	@cpoint = @ent.add_cpoint pt2
                            	end
                            
                            end
                            

                            plugins_menu = UI.menu("Plugins")
                            item = plugins_menu.add_item("Pinch Mover") {
                            Sketchup.active_model.select_tool Pinchmover.new
                            }`

                            I like mouse interaction and inferencing better than a dumb little inputbox πŸ’š
                            ... Now to get it to make only ONE cont.point ...
                            ... And THEN a way to select an endpoint for the tool to use as the centerpoint of the pinch πŸ˜’

                            1 Reply Last reply Reply Quote 0
                            • B Offline
                              BTM
                              last edited by

                              ; But now I think I know how to tackle both issues at once 😎

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

                                Hey, that's great! Its adding the construction point really well. Once its added, you have its position so you know where the pinch is going to. The second cpoint should indicate the vertex to be used.

                                I agree, you have to figure out those things, so I'm interested to hear how you do it!

                                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

                                  That works great! You have two separate points defined and stored for later use. Perfect. Now you have to decide how you want your script to move forward. Does it just begin automatically once the 2nd construction point is set? Or does it pop up a radius input box immediately after the 2nd point is added. Or does it just sit there until the user hits enter? Once they hit enter then it beings running. etc.

                                  So far so good. You've gotten past much of the mouse implementation. Now its on to transformations! WooHoo!

                                  Chris

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

                                  1 Reply Last reply Reply Quote 0
                                  • B Offline
                                    BTM
                                    last edited by

                                    **` require "sketchup.rb"

                                    class Pinchmover
                                    
                                    	def activate
                                    	
                                    	@model = Sketchup.active_model
                                    	@ent = @model.entities
                                    	@view = @model.active_view
                                    	@slct = @model.selection
                                    	@ip = Sketchup::InputPoint.new
                                    	@slct.clear
                                    	@first = 0
                                    	@second = 0
                                    	end
                                    
                                    	def onLButtonUp(flags, x, y, view)
                                    	
                                    		if @first == 0
                                    		ip1 = view.inputpoint x,y
                                    		pt1 = ip1.position
                                    		pt2 = Geom::Point3d.new pt1
                                    		@cpoint = @ent.add_cpoint pt2
                                    		@first = 1
                                    		@second = 1
                                    		
                                    		elsif @second == 1
                                    		ip2 = view.inputpoint x,y
                                    		pt3 = ip2.position
                                    		pt4 = Geom::Point3d.new pt3
                                    		@cpoint2 = @ent.add_cpoint pt4
                                    		@second = 2
                                    		end
                                    	end
                                    	
                                    	def onReturn(view) #Unnecessary, I just want to see if it's working.
                                    	UI.messagebox @cpoint
                                    	UI.messagebox @cpoint2
                                    	end
                                    end
                                    

                                    plugins_menu = UI.menu("Plugins")
                                    item = plugins_menu.add_item("Pinch Mover") {
                                    Sketchup.active_model.select_tool Pinchmover.new
                                    }`**
                                    πŸ˜„
                                    ... So?

                                    1 Reply Last reply Reply Quote 0
                                    • B Offline
                                      BTM
                                      last edited by

                                      I edited that last post about 30 seconds ago, so that it would have different variables to repeat. I don't know if it'll help, but I thought it would be a good idea.

                                      1 Reply Last reply Reply Quote 0
                                      • ely862meE Offline
                                        ely862me
                                        last edited by

                                        i don t know where to ask so i ll ask here...is there any chance to make a small code or plugin for deselecting a line or something else without zooming out and click away from model..
                                        i was thinking to rewrite the esc key sketchup function (..if u are in a group or is selected a group by pressing esc the group is deselected or is closed )...i would like by hitting the esc key to deselect the selected geometry

                                        Sorry for bad phrases πŸ˜„
                                        Thanks!

                                        Elisei

                                        Elisei (sketchupper)


                                        Before no life was done on Earth it was THE LIFE ITSELF...GOD
                                        Come and See EliseiDesign

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

                                          You can go ahead and start a new thread generally for questions like that... πŸ˜„

                                          The answer is ctrl-t. Deselect is already built into SketchUp, and that is the default shortcut key. If it doesn't work, then you've probably mapped it to something else. Go re-map it to they key that you want.

                                          Chris

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

                                          1 Reply Last reply Reply Quote 0
                                          • B Offline
                                            BTM
                                            last edited by

                                            Well, first of all, the plugin would be easy. Unfortunately though, you'd have to add a shortcut key to cet plugin, because, as far as I know, plugins seem to work only when they are in use. Unless it's somehow possible with initialize. πŸ˜•

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

                                            Advertisement