• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Determine zoom level through API

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 253 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.
  • T Offline
    timc
    last edited by 28 Sept 2009, 20:47

    Is there a way to determine the zoom level through the Sketchup API?

    I am trying to emulate the way the circle drawing tool displays a circle around the current mouse position. I can display a circle with ease, but the circle gets larger as I zoom in. I want the circle to remain the same size despite how far I zoom in or out.

    Any help would be appreciated, Thanks.

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 28 Sept 2009, 20:54

      You drawing stuff on the viewport from a Tool? Or are you drawing geometry?

      For drawing 2D stuff on the viewport you can use view.pixels_to_model http://code.google.com/apis/sketchup/docs/ourdoc/view.html#pixels_to_model

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

      1 Reply Last reply Reply Quote 0
      • T Online
        TIG Moderator
        last edited by 28 Sept 2009, 21:12

        @timc said:

        Is there a way to determine the zoom level through the Sketchup API?
        I am trying to emulate the way the circle drawing tool displays a circle around the current mouse position. I can display a circle with ease, but the circle gets larger as I zoom in. I want the circle to remain the same size despite how far I zoom in or out.
        Any help would be appreciated, Thanks.

        Why zoom level ? This method draws a fixed size circle ??

        
        def draw(view)
          ###make the circle data here, as an array of points, and them in view.draw_polyline(points) to make the circle...
        end#def
        
        

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          timc
          last edited by 29 Sept 2009, 12:33

          This is the code I'm using

          #This is what I have in the draw method of my tool
          def draw(view)
          	#@temp = the current mouse location. it is set in the mousemove method.			
          	@normal = view.camera.direction
          	@pts_circle = circle_points(@temp.position, @normal, 10, 24)
          	view.drawing_color = "blue"
          	view.draw_polyline(@pts_circle)
          end 
          
          #This is a function I found that creates the points needed to draw a circle
          def circle_points(center, normal, radius, numseg)
          	# Get the x and y axes
          	axes = Geom;;Vector3d.new(normal).axes
          	xaxis = axes[0]
          	yaxis = axes[1]
          	zaxis = axes[2]
          	    
          	xaxis.length = radius
          	yaxis.length = radius
          
          	# compute the points
          	da = (Math;;PI * 2) / numseg
          	pts = []
          	for i in 0..numseg do
          		angle = i * da
          		cosa = Math.cos(angle)
          		sina = Math.sin(angle)
          		vec = Geom;;Vector3d.linear_combination(cosa, xaxis, sina, yaxis)
          		pts.push(center + vec)
          	end
          	    
          	# close the circle
          	pts.push(pts[0].clone)
          
          	pts
          end
          

          If I use the mouse wheel to zoom while the tool is active the circle stays at a diameter of 10, so it appears larger if I zoom in and smaller if I zoom out.

          1 Reply Last reply Reply Quote 0
          • T Offline
            timc
            last edited by 29 Sept 2009, 12:36

            Thank you thomthom, that is exactly what I was looking for.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            1 / 1
            • First post
              1/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement