sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    A clone of an active_view.camera

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 3 Posters 352 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
      tomasz
      last edited by

      In my script I want to store an active_view.camera and restore it later on.

      When I use regular:

      stored_camera=Sketchup.active_model.active_view.camera
      ...
      modifying the view
      ...
      Sketchup.active_model.active_view.camera=stored_camera
      

      This does not restore camera, because the stored_camera just references the current_view.camera

      So I have done a copy of the camera object:

      stored_camera=Sketchup.active_model.active_view.camera.clone
      ...
      modifying the view
      ...
      Sketchup.active_model.active_view.camera=stored_camera
      

      This gives me an error:
      #<TypeError: reference to deleted Camera>

      I have tried Marshal::load(Marshal.dump(active_view.camera)) but the camera has no such a method.

      The question is : how can I successfully store current_view.camera?
      I know that it could be done by doing what Marshal is supposed to do, but we do not have access to all camera parameters (2p perspectives).

      Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

        Have you tried .dup ?

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

        1 Reply Last reply Reply Quote 0
        • T Offline
          tomasz
          last edited by

          @thomthom said:

          Have you tried .dup ?

          Same thing. Object already deleted.

          Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomasz
            last edited by

            I have found a solution, but will be thankful for a simpler, if such exists.

            I can create a temp_scene, make modifications to a view and then set selected_scene=temp_scene and delete it. Can be done with undo as well.

            Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              If you remember the current camera's data then later on you can simply make a new camera using those ?
              camera = model.active_view.camera eye = camera.eye target = camera.target up = camera.up pers = camera.perspective? fov = camera.fov

              change stuff including the view's camera details...###

              new_camera = Sketchup::Camera.new(eye, target, up, pers, fov)
              The 'new_camera' is now a 'clone' of the original 'camera'...
              model.active_view.camera = new_camera
              now sets the camera back as it was initially...

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                tomasz
                last edited by

                @tig said:

                If you remember the current camera's data then later on you can simply make a new camera using those ?

                @unknownuser said:

                I know that it could be done by doing what Marshal is supposed to do, but we do not have access to all camera parameters (2p perspectives).

                Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  The 2pt perspective is not an accessible camera parameter.
                  No more that Sketchup.send_action("viewTop:") or Sketchup.send_action("viewPerspective:") is... the camera settings only change for the eye/target/up when a '2pt Perspective' is evoked...
                  A 2pt Perspective is a 3D view with perspective 'off' [parallel projection] with a specific eye point / target / up that gives no distortion in 3D when perspective is 'off' - therefore doesn't saving the settings I listed duplicate a 2pt anyway - IF the camera's view it is one, because the camera is set so ??
                  If there were a Sketchup.send_action("viewPerspective2pt:") to set it [and there's not] then there's still no way of establishing if the view was in '2pt' anyway - other than the camera's parameters.....

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    tomasz
                    last edited by

                    @tig said:

                    The 2pt perspective is not an accessible camera parameter.

                    Unfortunately it is a camera parameter.
                    cx cy and Scale describe how much the 2d image has been shifted and zoomed in\out.
                    They are not being accessible from Ruby.


                    CameraProperties.png

                    Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      But it is a transient setting!
                      If you click in the view it evaporates...
                      It would be good if it were accessible but it is pretty transient...

                      TIG

                      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