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

    Questions about realization of tools

    Scheduled Pinned Locked Moved Developers' Forum
    20 Posts 4 Posters 370 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.
    • D Offline
      dacastror
      last edited by

      @thomthom said:

      Threads doesn't work well in SketchUp Ruby. It's Ruby 1.8 and they are not true threads.

      I did not know this 😲, thanks

      1 Reply Last reply Reply Quote 0
      • D Offline
        dacastror
        last edited by

        I give up, I can not understand how to use view.pickray x, y for the intersection with the XY, XZ and YZ, and thereby be able to guide a tool, really I can not see how this is done 😞

        I could only understand that returns two points, one coincides with the point of view and the other (I think) is a vector pointing toward the cursor, but do not understand how to use this to get the intersection with the respective flat front or behind me

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          View.pickray() can take ANY screen co-ordinate (it can be, or may not be the mouse position.)

          It returns a ray

          @unknownuser said:

          A ray is a two element array containing a point and a vector [ Geom::Point3d, Geom::Vector3d ]. The point defines the start point of the ray and the vector defines the direction.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            Perhaps you wish to use model#raytest ?

            It can return objects it hits.

            View#pickray() does not, by itself, "hit" anything, but could be used for the 1st argument to Model#raytest().

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • D Offline
              dacastror
              last edited by

              Guys, how to remove an observer of tools? I created an observer slightly modifying the example shown in the API

              
              class MyToolsObserver < Sketchup;;ToolsObserver
                 def onActiveToolChanged(tools, tool_name, tool_id)
                    if tool_id == 21100
                       puts "tool x"
                    end
                 end
              end
              
              Sketchup.active_model.tools.add_observer(MyToolsObserver.new)
              
              

              I thought you could with something like this:

              Sketchup.active_model.tools.remove_observer(MyToolsObserver)

              What is the correct way to remove this observer?

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                Keep a reference to the observer instance.

                <span class="syntaxdefault"><br /></span><span class="syntaxkeyword">@</span><span class="syntaxdefault">tool_observer&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">MyToolsObserver</span><span class="syntaxkeyword">.new<br /><br /></span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">tools</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_observer</span><span class="syntaxkeyword">(@</span><span class="syntaxdefault">tool_observer</span><span class="syntaxkeyword">)<br /><br /></span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">tools</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">remove_observer</span><span class="syntaxkeyword">(@</span><span class="syntaxdefault">tool_observer</span><span class="syntaxkeyword">)<br />&nbsp;</span><span class="syntaxdefault"></span>
                

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • D Offline
                  dacastror
                  last edited by

                  @dan rathbun said:

                  A ray is a two element array containing a point and a vector [ Geom::Point3d, Geom::Vector3d ]. The point defines the start point of the ray and the vector defines the direction.

                  Thanks Dan, I now understand better 😄

                  @dan rathbun said:

                  Perhaps you wish to use model#raytest ?
                  It can return objects it hits.
                  View#pickray() does not, by itself, "hit" anything, but could be used for the 1st argument to Model#raytest().

                  I've never used it, looks interesting I'll give a look.
                  For now solve the problem using the parametric form of the line;

                  x = x0 + ta
                  y = y0 + t
                  b
                  z = z0 + t*c

                  in my case a, b, c is associated with Geom :: Vector3D (parallel to the line)
                  and x0, y0, z0 is associated with Geom :: Point3D (content in the line)
                  the intersection with plane z=0 (XY plane), for example would be

                  
                  ray = view.pickray x, y  #ray[0] -> Point3D, ray[1] -> Vector3d
                  if ray[1].z.abs>0
                     z1 = 0 #Interesting plane
                     t1 = (z1-ray[0].z)/ray[1].z
                     x1 = ray[0].x + t1*ray[1].x
                     y1 = ray[0].y + t1*ray[1].y 
                  end
                  #x1,y1,z1 are coordinates of the point of intersection with the plane
                  
                  

                  For the other two planes is very similar, although in my case I want to compare the different distances of the planes to the point of "eye" for this I did the following

                  
                  ray = view.pickray x, y
                  
                  if ray[1].z.abs>0
                     z1 = 0 #Interesting plane
                     t1 = (z1-ray[0].z)/ray[1].z
                     d1 = (t1*ray[1].x)**2 + (t1*ray[1].y)**2 + (z1-ray[0].z)**2
                  end
                  #d1 is the square of the distance from the eye to the plane
                  
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    dacastror
                    last edited by

                    Thom thank you very much, really I could not understand how to do this 👍 😄

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      The API doc examples are confusing. One learn the hard way.

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        dacastror
                        last edited by

                        is true, on several occasions have been very frustrating these examples

                        error

                        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