• Login
sketchucation logo sketchucation
  • Login
πŸ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

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 18 May 2009, 19:19

    **` 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 18 May 2009, 19:20

      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
      • E Offline
        ely862me
        last edited by 18 May 2009, 19:27

        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
        • C Offline
          Chris Fullmer
          last edited by 18 May 2009, 19:32

          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 18 May 2009, 19:36

            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
            • E Offline
              ely862me
              last edited by 18 May 2009, 19:37

              U re the MAN ..it works..
              I asked some time ago and the answer was zooming out and click away..
              Thanks for the tip..
              Btw you are doing a great job with all these plugins ..Thanks for that too!

              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
              • B Offline
                BTM
                last edited by 18 May 2009, 19:40

                ... For me, shift alt a.

                1 Reply Last reply Reply Quote 0
                • B Offline
                  BTM
                  last edited by 18 May 2009, 21:45

                  Okay. Here's my big issue, I knew I'd end up having.

                  this is the part I added to the end of the elsif in onLButtonUp:
                  prompts = ["Radius="] defaults = [ 0.0.to_l] list = [""] results = UI.inputbox prompts, defaults, list, "Please input desired radius." @rad= results

                  Now, HOW can I go through all the active points in the model**(to see which ones are within the distance of @rad from @cpoint2 in the future)**? I can't use .typename, because endpoints aren't really entities, so I'm stuck.

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    Chris Fullmer
                    last edited by 18 May 2009, 22:05

                    This is what I use to iterate through a model for vertices.

                    
                    ents = Sketchup.active_model.active_entities
                    verts = []
                    
                    ents.each do |e|
                     if e.typename == "Edge"
                      verts << e.start
                      verts << e.end
                     end
                    end
                    
                    verts.uniq!
                    

                    That adds every start vert and every end vert to the array, then .uniq! removes all duplicates.

                    Now you have an array of all vertices in an array. This is the transformation method you will need to use in this script:

                    http://code.google.com/apis/sketchup/docs/ourdoc/entities.html#transform_by_vectors

                    There's lots of ways to transform things, but most of them transform one object at a time, which won't work for what your doing (I don't think it will at least). So this transform is cool because it does it all at once. What you need to create is an array of vectors that correspond to your array of vertices. The vector should be the vector that your vertex will move. Hope that helps with the next step,

                    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 18 May 2009, 22:10

                      Ah, thanks for that! πŸ˜„ I don't see why google doesn't just add a method in entities for vertices (Or whatever they're called, points). Heck, they should have it so you can select them with the selection tool IMHO. Anyways, thanks again; I would have been ages trying to figure that out πŸ˜†

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 19 May 2009, 05:58

                        @chris fullmer said:

                        That adds every start vert and every end vert to the array, then .uniq! removes all duplicates.

                        Have you ever used the Set class to keep track of objects? http://code.google.com/apis/sketchup/docs/ourdoc/set.html
                        I haven't, but I have a feeling it could be useful for this as it's supposed to only allow unique objects in the list.

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

                        1 Reply Last reply Reply Quote 0
                        • C Offline
                          Chris Fullmer
                          last edited by 19 May 2009, 06:01

                          Oh really? That's cool. I have used it once in a script, but I didn't realize it would not allow duplicates.

                          I'm going to go read through that Class again. Sounds like it might be more helpful than I had realized. Thanks Thom,

                          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 19 May 2009, 10:30

                            ... Just found another problem πŸ˜’

                            How do you turn @rad, which ends up as an array with the length in inches in it, back into a length?
                            i.e. @rad = results.to_l doesn't work.

                            1 Reply Last reply Reply Quote 0
                            • C Offline
                              Chris Fullmer
                              last edited by 19 May 2009, 16:52

                              That's what I was saying was the problem in that first bit of script you showed - you can't vconvert an array to_i, or to_l. I'm not sure why it was working on your end. Its ok though, its an easy solution.

                              So results is an array of whatever was in the inputbox. In that array, the radius is in the zero position. So when you save @rad, just convert it to a length:

                              @rad = results[0].to_l

                              Now @rad is not an array. Its just a length. Hope that helps,

                              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 19 May 2009, 23:22

                                [0]. πŸ‘Š Man, I KNEW it was going to be something completely obvious. The first item in the array! Why can't I think of these things! πŸ˜†

                                1 Reply Last reply Reply Quote 0
                                • B Offline
                                  BTM
                                  last edited by 20 May 2009, 01:06

                                  Issue I'm having NOW. How to implement .transform_by_vectors. I have the Set I want to transform, @dvert, and the vector, @vect (Will add math to it later), but I don't know how to get it to work. πŸ˜’
                                  What I have in there currently is really stupid, It was just what I had typed in it when I took the screenshot. What I'm trying to get it to do should be obvious enough. Also, should the line above it be @cpoint.position and @cpoint2.position or not?
                                  I've tried @ent.transform_to_vectors @dvert, @vect, @dvert.transform_to_vectors @vect, etc., etc.
                                  πŸ˜•

                                  1 Reply Last reply Reply Quote 0
                                  • C Offline
                                    Chris Fullmer
                                    last edited by 20 May 2009, 03:06

                                    You're really close. It looks like the @verts should be populating correctly. And also @dvert looks like its being populated correctly too.

                                    The line @vect = cpoint.vector_to @cpoint2 wont work because your @vect has to be an array of vectors (not just a single vector) with the same amount of elements in it as your @dverts. So after setting the @dvert Set, you need to iterate through them and define a vector for each that will tell it how far to move. Lets try it without math at first. Here is an example.

                                    @dvert.each do |e| @vect.insert e.position.vector_to [0,0,0] end

                                    So now you have a Set of vertices (lets say there are 30 of them in that array). And you also have the @vect Set and it has 30 vectors, and they correspond with the vertices in @dvert. That is what you need to give to the transform_by_vector. So your transform_by_vectors is:

                                    @ents.transform_by_vectors @dverts.to_a, @vect.to_a

                                    I'm not sure that you need to the .to_a conversion on those, but I think you might because they are actually sets, not arrays. And transform by vectors is expecting to get arrays.

                                    Hope that makes sense (and I hope its right, I haven't tested that code)

                                    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
                                      RickW
                                      last edited by 20 May 2009, 15:50

                                      Chris,

                                      If BTM has certain of my scripts installed, he will have array_to.rb which adds methods .to_i and .to_f to the Array class to convert all members to integers or floats. That could be why array.to_i worked for him and not for you.

                                      RickW
                                      [www.smustard.com](http://www.smustard.com)

                                      1 Reply Last reply Reply Quote 0
                                      • C Offline
                                        Chris Fullmer
                                        last edited by 20 May 2009, 16:07

                                        OHH!! I get it now. I couldn't think of what would make that work for him. Thank you for explaining that one Rick.

                                        I also could never quite figure out what that script did (before I had started using Ruby). It all makes sense now, thanks for the heads up Rick!

                                        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 22 May 2009, 02:04

                                          I think I'm close, but it still isn't working.

                                          ` %(#600000)[****require "sketchup.rb"
                                          #-------------------------------------------------------------------------------
                                          class Pinchmover
                                          #-------------------------------------------------------------------------------
                                          def activate
                                          @model = Sketchup.active_model
                                          @ent = @model.entities
                                          @view = @model.active_view
                                          @slct = @model.selection
                                          @slct.clear
                                          @vect = Set.new
                                          @verts = Set.new
                                          @dvert = Set.new

                                          - - - - - - - - - - - - - - - - - - - -

                                          	@thing = 0
                                          

                                          - - - - - - - - - - - - - - - - - - - -

                                          	end
                                          

                                          #-------------------------------------------------------------------------------
                                          def onLButtonUp(flags, x, y, view)

                                          - - - - - - - - - - - - - - - - - - - -

                                          		if @thing == 0
                                          		ip1 = view.inputpoint x,y
                                          		pt1 = ip1.position
                                          		pt2 = Geom::Point3d.new pt1
                                          		@cpoint = @ent.add_cpoint pt2
                                          		@thing = 1
                                          		end
                                          

                                          - - - - - - - - - - - - - - - - - - - -

                                          		if @thing == 1
                                          		ip2 = view.inputpoint x,y
                                          		pt3 = ip2.position
                                          		pt4 = Geom::Point3d.new pt3
                                          		@cpoint2 = @ent.add_cpoint pt4
                                          

                                          - - - - - - - - - - - - - - - - - - - -

                                          			prompts = ["Radius="]
                                          			defaults = [ 0.0.to_l]
                                          			list = [""]
                                          			results = UI.inputbox prompts, defaults, list, "Please input desired radius."
                                          		@rad= results[0].to_l
                                          

                                          - - - - - - - - - - - - - - - - - - - -

                                          			@ent.each do |e|
                                          				if e.typename == "Edge"
                                          				@verts.insert e.start
                                          				@verts.insert e.end
                                          				end
                                          			end
                                          

                                          - - - - - - - - - - - - - - - - - - - -

                                          			@verts.each do |v|
                                          			dist = v.position.distance @cpoint.position
                                          				if dist < @rad
                                          				@dvert.insert v
                                          				end
                                          			end
                                          

                                          - - - - - - - - - - - - - - - - - - - -

                                          			@dvert.each do |d| # Doesn't seem to work.
                                          			vec = @cpoint.position.vector_to @cpoint2.position
                                          			@vect.insert vec
                                          			end
                                          		@affected = @ent.transform_by_vectors @dvert.to_a, @vect.to_a
                                          		@thing = 2
                                          		end
                                          

                                          - - - - - - - - - - - - - - - - - - - -

                                          	end
                                          

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

                                          ... WHY can't I get it to work? πŸ˜† I really think the biggest problem could be in how it's set up overall, or in the last few lines, but can't be sure. I've been trying to get it to work on my own for some time now, to no avail. Anyone know what I've done completely wrong? πŸ˜•

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

                                          Advertisement