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

    How to snap?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 489 Views 4 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.
    • N Offline
      NewOne
      last edited by

      Hy!

      When working in SketchUP,drawing a line or something, the cursor snaps on edges, faces or axes origin and there appears a coloured dot. Is this an automatic behaviour of drawing action or is something what can be controlled?
      I want to click on screen and get the 3d coordinates of that position. I made a small script which returns me the coordinates, but I can't be sure if I'm on a face, or edge... I'd like to force the cursor to snap on near objects and see that coloured dot.
      Thank you.

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Hi NewOne,

        Use an InputPoint if you need inferencing; and see the linetool.rb in the Plugins/Examples folder for an example.

        Hopefully someone who knows the tricks for using InputPoints can fill in more about using one.

        Hi

        1 Reply Last reply Reply Quote 0
        • chrisglasierC Offline
          chrisglasier
          last edited by

          @newone said:

          I want to click on screen and get the 3d coordinates of that position. I made a small script which returns me the coordinates ...

          Would you be kind enough to share the script? It would be really useful to help make my namesets bilateral.

          Thanks

          Chris

          With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

          1 Reply Last reply Reply Quote 0
          • N Offline
            NewOne
            last edited by

            @chrisglasier said:

            @newone said:

            I want to click on screen and get the 3d coordinates of that position. I made a small script which returns me the coordinates ...

            Would you be kind enough to share the script? It would be really useful to help make my namesets bilateral.

            Thanks

            Chris

            It's no big thing yet. I've just used InputPoint on click.
            Something like this:

            
            def onLButtonDown(flags, x, y, view)
                    @ip.pick view, x, y
                    if( @ip.valid? )
            		position = @ip.position
                    end
            end
            
            
            1 Reply Last reply Reply Quote 0
            • N Offline
              NewOne
              last edited by

              @jim said:

              Hi NewOne,

              Use an InputPoint if you need inferencing; and see the linetool.rb in the Plugins/Examples folder for an example.

              Hopefully someone who knows the tricks for using InputPoints can fill in more about using one.

              That's where I started, but everything is confusing... That example tries to explain something, but in the end i'm even more confused.
              Why are used three InputPoints when, for drawing a line two points are needed? -here is a part of code

              def activate
                  @ip1 = Sketchup;;InputPoint.new
                  @ip2 = Sketchup;;InputPoint.new
                  @ip = Sketchup;;InputPoint.new
                  @drawn = false
              
                  Sketchup;;set_status_text $exStrings.GetString("Length"), SB_VCB_LABEL
                  
                  self.reset(nil)
              end
              

              Ok, this is not about my principal question, but one of dizzy things in that script.
              And I could not figure out where is the inferencing at point, just the constrain modifier key inference... that's why I thought the inferencing at point is an automatic behaviour and appears just when the tool makes a drawing.

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                Here is thread about InputPoint - it seems you can pass an argument (Point3d) that it will use as a point to infer from.

                301 Moved Permanently

                favicon

                (www.sketchucation.com)

                Hi

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

                  The utility_tools.rb is shorter than the linetool.rb and it has a great script already made that does this. If you go to Tool>Utilities>Query Tool that is a tool made by @Last that does exactly what you want. And its inside the Utilities folder in plugins so you can open it and take it apart. I'll see if I can post a veryt stripped down version of the code - the minimal amount of stuff to keep it working so its not confusing (its something I'm working on currently for myself because I'm going through this exact same process right now and I too am very confused, but catching on little by little). So give me a little while maybe I can post that striped down version of a working tool.

                  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

                    This is an entire working script, from start to finish. Save it as a .rb file and its ready to go. It installs itself as "Plugins>Mouse Tools". There are no comments in the code whatsoever. I took them all out because the ones that were there were not terribly helpful, mostly just made it hard to read the code straight through. I believe that this code is more complex than absolutely necessary because it adds a few checks to make sure it does not call the draw method unnecessarily. Hopefully this helps. I'm still confused what portions of this code are doing....

                    require 'sketchup.rb'
                    
                    class Clf_mousetools
                    
                    def activate
                        @ip = Sketchup;;InputPoint.new
                        @iptemp = Sketchup;;InputPoint.new
                        @displayed = false
                    end
                    
                    def onMouseMove(flags, x, y, view)
                        pos = @ip.position
                    	Sketchup;;set_status_text("#{pos.x}, #{pos.y}, #{pos.z}")    
                        @iptemp.pick view, x, y
                        if( @iptemp.valid? )
                            changed = @iptemp != @ip
                            @ip.copy! @iptemp
                            pos = @ip.position;        	
                            if( changed and (@ip.display? or @displayed) )
                                view.invalidate
                            end
                        end
                    end
                    
                    def draw(view)
                        if( @ip.valid? && @ip.display? )
                            @ip.draw view
                            @displayed = true
                        else
                            @displayed = false
                        end
                    end
                    end
                    
                    if !file_loaded?(__FILE__) then
                    	UI.menu("Plugins").add_item("Mouse Tools") { Sketchup.active_model.select_tool Clf_mousetools.new }
                    end
                    file_loaded(__FILE__)
                    

                    Chris

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

                    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