Determine zoom level through API
-
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.
-
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 -
@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
-
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.
-
Thank you thomthom, that is exactly what I was looking for.
Advertisement