Waiting for Sketchup.send_action to complete before continuing

Because I remember being involved with another topic in which we discussed that Sketchup::Camera#clone is simply inherited from Object and does not create a new Camera object (that is an exact copy of the original).
(ADD: [topic was] Camera Object Cloning Issue - Same as new with no arguments )

BUT, I forgot that the API implemented a ::new constructor for the class.

Anyhow, I was concerned that the reference to the view’s camera object that is returned by view.camera will not be a NEW object, so I thought it safer to store the 3 “descriptors” for the camera.set method. I have other code that I had to do this, so I was “running on past work”.

However, testing at the console, I see that view.camera returns a new object (on the Ruby-side) each time it is called, even when nothing has changed.

Testing at the console of v16
@cam = view.camera
change the view to “Top”
view.camera= @cam
nothing happens !

This is what I thot would happen, that the reference was pointing at the C-side view object what ever it is, and when it’s properties change, the reference is not magically made to point at a new object (on the Ruby-side) with the old properties.

So I forgot that there was a camera constructor, but in order to leverage this we’d still need to extract the 3 “descriptor” properties, viz:

  def remember_view()
    view = Sketchup.active_model.active_view
    cam = view.camera
    @camera = Sketchup::Camera::new( cam.eye,cam.target,cam.up )
    view.add_observer(@spy)
  end

NOW, we can just set the camera back to the previous camera without the array and the splat operator rigmarole:

  def restore_view()
    view = Sketchup.active_model.active_view
    view.remove_observer(@spy)
    restore_layers()
    view.camera= @camera
  end

My original actually takes a bit less code. If you find it easier, well okay use what you will. (Ruby is multi-paradigm.)

I just remember that @cam = view.camera would not work and that the 3 properties needed to be saved, and I find it easier to use the array.

Now if they’d implement a camera.clone method I’d promote that instead. I even wrote a test for that. I suppose I’d should attach it to a feature request and log it.


Now he did not even ask for that feature, but since others were encouraging him to change the camera, I thot I’d just include it as best practice. (Users might be upset if their previous view was not restored.)

You are free to prove me wrong here in any aspect and post an example of your own.