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

    Cursor Position To November92

    Scheduled Pinned Locked Moved SketchyPhysics
    5 Posts 3 Posters 982 Views 3 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.
    • A Offline
      Anton_S
      last edited by Anton_S

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

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

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

        πŸ˜•

        TIG

        1 Reply Last reply Reply Quote 0
        • M Offline
          MrDailyBlah
          last edited by

          NewtonServer.magnetMove? what is NewtonServer? is it a module in SP or sumthing?

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            @mrdailyblah said:

            NewtonServer.magnetMove? what is NewtonServer? is it a module in SP or sumthing?
            Yes it is.

            TIG

            1 Reply Last reply Reply Quote 0
            • A Offline
              Anton_S
              last edited by

              NewtonServer is a dll library to newton physics stuff

              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