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

      ; 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
                    • ely862meE Offline
                      ely862me
                      last edited by

                      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

                        ... For me, shift alt a.

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

                          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
                          • Chris FullmerC Offline
                            Chris Fullmer
                            last edited by

                            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

                              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
                              • thomthomT Offline
                                thomthom
                                last edited by

                                @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
                                • Chris FullmerC Offline
                                  Chris Fullmer
                                  last edited by

                                  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

                                    ... 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
                                    • Chris FullmerC Offline
                                      Chris Fullmer
                                      last edited by

                                      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

                                        [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

                                          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
                                          • Chris FullmerC Offline
                                            Chris Fullmer
                                            last edited by

                                            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
                                            • 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