Extract camera position
-
Hey guys.
what requirements to i extract position x,y,z of the camera and put them in a blank sentence?
For example:camera:
vx, vy, vz
and my sentence is:
("camera location = (" + l2str(vx) + ", " + l2str(vy) + ", " + l2str(vz) + ")")
-
Try this...
@@model = Sketchup.active_model ; peye = @@model.active_view.camera.eye ; UI.messagebox("Camera location = #{peye}") ;
Cheers!
-
nice code!
and how i put these values to enter into vx, vy and vz? -
Also Ref: [ Code ] save Camera properties method
Also on PC ONLY there is a built-in Camera properties dialog.
require('sketchup.rb') unless RUBY_PLATFORM =~ /(darwin)/i # not for Mac ! tag = "Camera Properties;#{File.basename(__FILE__)}" unless file_loaded?(tag) UI.menu('Camera').add_separator UI.menu('Camera').add_item('Camera Properties...'){ Sketchup.send_action(10624) # MS Windows ONLY } file_loaded(tag) end end
-
@greenskp said:
nice code!
and how i put these values to enter into vx, vy and vz?cam = Sketchup.active_model.active_view.camera vx,vy,vz = cam.eye.to_a
and ...
puts("Camera location = #{cam.eye.to_s}") %(#000000)[>>] %(#008000)[Camera location = (0", 0", 1")]
(when units are Inches... but if units are mm, then output is:
%(#000000)[>>] %(#008000)[Camera location = (0mm, 0mm, 25.4mm)]
-
I think you mean like this...
vx = peye.x
vy = peye.y
vz = peye.z@@model = Sketchup.active_model ; peye = @@model.active_view.camera.eye ; vx = peye.x vy = peye.y vz = peye.z UI.messagebox("Camera location = #{vx}, #{vy}, #{vz}") ;
Cheers!
-
Thanks Renderiza but the code returns me this result: (~ 1,91, ~ 1,63, ~ 0,06)
It can return results like this? (1.91, 1.63, 0.06)
One more thing. Whit this code i can get camera target position?
It´s possible that to each Scene created i have different coordinates?@unknownuser said:
@@model = Sketchup.active_model ; > > peye = @@model.active_view.camera.eye ; > > vx = peye.x > vy = peye.y > vz = peye.z > > UI.messagebox("Camera location = #{vx}, #{vy}, #{vz}") ;
Cheers!
Thanks for answer Dan Rathbun. I will test your code tomorrow.
-
You can remove the "~" symbol by doing this...
vx = peye.x.to_feet
vy = peye.y.to_feet
vz = peye.z.to_feetor
vx = peye.x.to_mm
vy = peye.y.to_mm
vz = peye.z.to_mmBUT! problem is that the number of decimals added might be a lot. I will like to know if there is a way to reduce the number of decimals to only two places.
cheers!
-
Here is the SOLUTION!
peye = @@model.active_view.camera.eye ; vx = peye.x.to_feet vy = peye.y.to_feet vz = peye.z.to_feet dp=2 vxa = (vx*10**dp).round*10**-dp vya = (vy*10**dp).round*10**-dp vza = (vz*10**dp).round*10**-dp UI.messagebox("Camera location = #{vxa}, #{vya}, #{vza}") ;
Note:
The user TIG posted the solution in this site...https://groups.google.com/forum/?fromgroups=#!topic/sketchupruby/623a05vZfysSo thanks TIG!
-
@unknownuser said:
You can remove the "~" symbol by doing this...
vx = peye.x.to_feet
vy = peye.y.to_feet
vz = peye.z.to_feetor
vx = peye.x.to_mm
vy = peye.y.to_mm
vz = peye.z.to_mmBUT! problem is that the number of decimals added might be a lot. I will like to know if there is a way to reduce the number of decimals to only two places.
cheers!
The ~ is because the X, Y and Z values are of the Length class, which when converted to string will use of the model settings for representing units. This is normally what users expect to see so I'd encourage to not change that.
More info on units in SketchUp: http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/
-
@greenskp said:
One more thing. Whit this code i can get camera target position?
Dan Rathbun posted a ref link that have things like target, direction, ect
example
ptarget = @@model.active_view.camera.target ;
@greenskp said:
It´s possible that to each Scene created i have different coordinates?
Not sure what you mean by this. If you click remember camera position in scene manager then yes you will change camera placement with scene.
Cheers!
Note: Thanks thomthom for explaining why that happened!
Advertisement