How to snap?
-
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. -
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.
-
@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
-
@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
-
@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 codedef 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. -
Here is thread about InputPoint - it seems you can pass an argument (Point3d) that it will use as a point to infer from.
-
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
-
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
Advertisement