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

    Extract camera position

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 4 Posters 309 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.
    • greenskpG Offline
      greenskp
      last edited by

      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) + ")")

      1 Reply Last reply Reply Quote 0
      • renderizaR Offline
        renderiza
        last edited by

        Try this...

        @@model = Sketchup.active_model ;
        
        peye = @@model.active_view.camera.eye ;
        
        UI.messagebox("Camera location = #{peye}") ;
        

        Cheers!

        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

        1 Reply Last reply Reply Quote 0
        • greenskpG Offline
          greenskp
          last edited by

          nice code!
          and how i put these values to enter into vx, vy and vz?

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

            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
            

            💭

            I'm not here much anymore.

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

              @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'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • renderizaR Offline
                renderiza
                last edited by

                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!

                [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                1 Reply Last reply Reply Quote 0
                • greenskpG Offline
                  greenskp
                  last edited by

                  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.

                  1 Reply Last reply Reply Quote 0
                  • renderizaR Offline
                    renderiza
                    last edited by

                    You can remove the "~" symbol by doing this...

                    vx = peye.x.to_feet
                    vy = peye.y.to_feet
                    vz = peye.z.to_feet

                    or

                    vx = peye.x.to_mm
                    vy = peye.y.to_mm
                    vz = peye.z.to_mm

                    BUT! 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!

                    [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                    1 Reply Last reply Reply Quote 0
                    • renderizaR Offline
                      renderiza
                      last edited by

                      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/623a05vZfys

                      So thanks TIG!

                      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

                        @unknownuser said:

                        You can remove the "~" symbol by doing this...

                        vx = peye.x.to_feet
                        vy = peye.y.to_feet
                        vz = peye.z.to_feet

                        or

                        vx = peye.x.to_mm
                        vy = peye.y.to_mm
                        vz = peye.z.to_mm

                        BUT! 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/

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

                        1 Reply Last reply Reply Quote 0
                        • renderizaR Offline
                          renderiza
                          last edited by

                          @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!

                          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                          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