Cursor Position To November92
-
**This is the answer to November92, so don't think that this is a question or something.**First: My mouse command model is very old and now doesn't works, so to get the cursor position here is the new way:
SP is a tool writen by CPhillips that allows the user to see object in simulation.
This Tool has the Tool Functions writen into it(http://code.google.com/apis/sketchup/docs/ourdoc/tool.html). One of the functions is
deactivate- The Tool activated when the different tool is selected. For Example: Lets say you click play and then turned off the SketchyPhysicsTool Dialog. After that lets say you select key("space") and see that SP simulation canceled or discontinued. When you select key space, by default the user should get the black cursor that is the nil tool. Or lets say when select key("q"), the simulation quit's and the user gets the rotate tool. What if you want both tools to activate? - to do that the deactive function should not have a script in it that calls the reset SP Simulation. The tool also has the function "onMouseMove". This is the function that can return you the [x,y] cursor position, which is relative to Sketchup view. SP has a script writen to it that does something, but it doesn't has the variables in it that would record the cursor position and that would be allowed to be called from outside of a class. So to get them we can't write our own tool, because if we will then this tool would not be able to be called while SP simulation is running because the deactive function would be called. To do that we need to edit the SP SketchyPhysicsClient tool. So here is how to do it:Copy or write this to the scripted part.
onstart{ #### Variables #### $cursor_pos=[0,0] #### Loading File #### if defined?($tempfile_loaded)==nil then #prevent from loading more than once directory=Object;;Dir.pwd.split(";/")[0]+";/" tempfile=Object;;File.new(directory+"SUtempfile.rb","w+") tempfile.puts('module MSketchyPhysics3 class SketchyPhysicsClient def onMouseMove(flags,x,y,view) $cursor_pos=[x,y] #Here is our variable @mouseX=x @mouseY=y if @CursorMagnetBody==nil then return() end ip=Sketchup;;InputPoint.new ip.pick(view,x,y) if ip.valid? then if @pickedBody!=nil then @simulationContext.doOnMouse(;drag,@pickedBody,x,y) if getKeyState(VK_LSHIFT) then #project the input point on a plane described by our normal and center. ep=Geom.intersect_line_plane([view.camera.eye,ip.position],[@attachWorldLocation,view.camera.zaxis]) @attachWorldLocation=ep pos=ep else ep=Geom.intersect_line_plane([view.camera.eye,ip.position], [@attachWorldLocation,Z_AXIS]) pos=ep @attachWorldLocation=ep end @magnetLocation=pos if @CursorMagnet!=nil then NewtonServer.magnetMove(@CursorMagnet,pos.to_a.pack("f*")) end end end end #OnMouseMove end #class SketchyPhysicsClient end #module MSSketchyPhysics3') tempfile.close load(directory+"SUtempfile.rb") Object;;File.delete(directory+"SUtempfile.rb") $tempfile_loaded=true end #### Functions #### def getCursor(state=0) view=Sketchup.active_model.active_view #Shortcut case state when 0, "coordinates"; #cursor screen coordinates return($cursor_pos()) when 1, "position"; #3d Position return(view.inputpoint($cursor_position[0],$cursor_position[1]).position.to_a) when 2, "best_picked"; #Entity at which the cursor is pointing return(view.pick_helper.do_pick($cursor_position[0],$cursor_position[1]).best_picked.to_a) end end }
Now We can Use this getCursor Function to get its coordinates, 3d position, and best picked entity.
Ex: pos=getCursor(0)
Also Read GoogleSketcup API to understand it's Functions and try examining sketchy Physics Tool File in SP Folder
Recommend to download notepad++ - It the best,
go here: http://notepad-plus-plus.org/release/5.9.2 -
Anton
Please could you edit your post so it is easier to read.
Having it ALL in 'ruby' code doesn't help!
Split it into text, ruby and a code block...
AND explain the purpose of your post better - it is not very clear... at the moment I can't readily see if it's a statement, a question, a code-snippet or what ??? -
NewtonServer.magnetMove? what is NewtonServer? is it a module in SP or sumthing?
-
@mrdailyblah said:
NewtonServer.magnetMove? what is NewtonServer? is it a module in SP or sumthing?
Yes it is. -
NewtonServer is a dll library to newton physics stuff
Advertisement