• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Getting and iterating scene list?

Scheduled Pinned Locked Moved Developers' Forum
16 Posts 3 Posters 316 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.
  • H Offline
    HPW
    last edited by 14 Sept 2012, 11:42

    Hello,

    I do an automated ACAD-import and get some scenes converted from ACAD-views.

    Can I get a list with ruby of all existing scenes and iterate through the list
    and set each scene activ, zoom to the extents and then update the scene property.

    When I later click on the scene I get the correct view with all geometry in view.

    Regards

    Hans-Peter

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 14 Sept 2012, 11:47

      In earlier versions, Scenes where named Pages.

      To get list of scenes:
      Sketchup.ative_model.pages
      Returns a Sketchup::Pages collection object.
      https://developers.google.com/sketchup/docs/ourdoc/pages

      Iterate the collection which return Sketchup::Page objects.
      https://developers.google.com/sketchup/docs/ourdoc/page

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

      1 Reply Last reply Reply Quote 0
      • H Offline
        HPW
        last edited by 14 Sept 2012, 14:17

        Hello,

        Thanks for the hints.

        
         model = Sketchup.active_model
         pages = model.pages
         pages.each {|page|
            pages.selected_page = page
            view = model.active_view
            new_view = view.zoom_extents
            status = page.update(33) 
            }
        
        

        Iterating through the pages seems to work.
        But they have now all the same view.
        How can I get the view of the selected page first and then do the zoom extent on that view?
        The page have different viewing angle after import. That should be preserved and only zoomed to extent.
        I do not see a page.view or something else.

        Regards

        Hans-Peter

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 14 Sept 2012, 17:07

          When the SketchUp engine does things to the UI on the C++ side, it often returns the Ruby call immediately before things are complete on the C++ side.

          In this case, the C++ side is not done animating the camera, when the next Ruby statement executes.

          So you can try using Kernel.sleep calls to insert pauses. (Adjust till things work right.)

          require('sketchup.rb')
          
          module HPW
          
            module SceneUtility
          
              @@pages_menu = nil
          
              class << self # proxy class
          
                def scene_transitions?(model)
                  model.options['PageOptions']['ShowTransition']
                end
                
                def set_scene_transitions(model,bool=true)
                  bool =( bool ? true ; false )
                  model.options['PageOptions']['ShowTransition']= bool
                end
                
                def zoom_all_pages_to_extents()
                  model = Sketchup.active_model
                  pages = model.pages
                  trans = scene_transitions?(model)
                  set_scene_transitions(model,false) if trans
                  pages.each {|page|
                    pages.selected_page = page
                    Kernel.sleep(0.5)
                    model.active_view.zoom_extents
                    #status = page.update(33)
                    Sketchup.send_action('pageUpdate;')
                    Kernel.sleep(0.5)
                  }
                  set_scene_transitions(model,trans)
                end
              
              end # proxy class
          
              ### RUN ONCE
              unless file_loaded?(File.basename(__FILE__))
                #
                @@pages_menu = UI.menu('Plugins').add_submenu('Pages')
                @@pages_menu.add_item('Zoom All Pages To Extents') {
                  zoom_all_pages_to_extents()
                }
                file_loaded(File.basename(__FILE__))
                #
              end
          
            end # module SceneUtility
          
          end # module HPW
          

          If this does not work correctly.. then we'll have to implement a FrameChangeObserver.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 14 Sept 2012, 17:14

            Doesn't sleep freeze up SketchUp itself?

            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
              thomthom
              last edited by 14 Sept 2012, 17:17

              @thomthom said:

              Doesn't sleep freeze up SketchUp itself?

              Yes it does.

              puts 'foo'; Kernel.sleep(5); puts 'bar';
              SketchUp doesn't respond at all until sleep is over.

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

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 14 Sept 2012, 17:21

                @thomthom said:

                Doesn't sleep freeze up SketchUp itself?

                It should not freeze the C++ side, which should continue animating or zooming the camera. It should only pause the Ruby interpreter.

                And I likely showed more time than is needed in at least the first place in the example. The second place is dependent upon how many pages need updating thumbnails, etc.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • D Offline
                  Dan Rathbun
                  last edited by 14 Sept 2012, 17:22

                  @thomthom said:

                  @thomthom said:

                  Doesn't sleep freeze up SketchUp itself?

                  Yes it does.

                  puts 'foo'; Kernel.sleep(5); puts 'bar';
                  SketchUp doesn't respond at all until sleep is over.

                  Apples and Oranges.

                  puts is on the ruby side, ... of course sleep will pause between the two Ruby statements!

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 14 Sept 2012, 17:28

                    @dan rathbun said:

                    @thomthom said:

                    @thomthom said:

                    Doesn't sleep freeze up SketchUp itself?

                    Yes it does.

                    puts 'foo'; Kernel.sleep(5); puts 'bar';
                    SketchUp doesn't respond at all until sleep is over.

                    Apples and Oranges.

                    puts is on the ruby side, ... of course sleep will pause between the two Ruby statements!

                    I should have been more specific - I cannot interact with SketchUp until sleep is over. The puts statements where just visual clues to know when it was over.

                    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
                      thomthom
                      last edited by 14 Sept 2012, 17:30

                      @dan rathbun said:

                      @thomthom said:

                      Doesn't sleep freeze up SketchUp itself?

                      It should not freeze the C++ side, which should continue animating or zooming the camera. It should only pause the Ruby interpreter.

                      You didn't test it, did you?

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

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        Dan Rathbun
                        last edited by 14 Sept 2012, 17:31

                        It's probably not perfect,.. and I did say this:

                        @dan rathbun said:

                        If this does not work correctly.. then we'll have to implement a FrameChangeObserver.

                        I'd likely use a UI.start_timer block along with a FrameChangeObserver if the sleep did actually interfer (perhaps SketchUp cannot call ViewObserver or PageObserver instances during sleep call ??)

                        So.. you could be correct Thomas. This the ol' workaround thingummy again. I wish the API would finish doing certain things, before returning a value from many API method calls (like setting pages, etc.)

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          Dan Rathbun
                          last edited by 14 Sept 2012, 17:34

                          @thomthom said:

                          You didn't test it, did you?

                          Nope.. caught me!

                          I just whacked it out. 😳

                          I'll have to drink another cup of coffee, and put in a FrameChangeObserver

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            thomthom
                            last edited by 15 Sept 2012, 09:27

                            Rember, we cannot even use Ruby threads without blocking SketchUp. And wouldnt it be difficult for the Ruby engine to interact with the SketchUp engine and the entities if they ran in a separate thread/process?

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

                            1 Reply Last reply Reply Quote 0
                            • H Offline
                              HPW
                              last edited by 17 Sept 2012, 06:54

                              OK, things seems not so easy.
                              The scene tab even does first appear after a autosart ruby has run, so no way to access the scenes via shortcut.

                              Other idea: Scenes can store the camera loctation. So can a ruby calculate a new camera location for each scene and write the property.
                              This would not update the screen or change the visible scene. But next time the scene-change is used it updates to the new location.
                              And the new camera locations are stored for each scenes in onSave.

                              What Propertys does ZoomExtents set? Is there a equivalent in ruby to calculate the values in the same way?

                              Regards

                              Hans-Peter

                              1 Reply Last reply Reply Quote 0
                              • H Offline
                                HPW
                                last edited by 17 Sept 2012, 08:34

                                This does what I want:

                                
                                 model = Sketchup.active_model
                                 pages = model.pages
                                 pages.each {|page|
                                    pages.selected_page = page
                                    UI.messagebox("Scene; "+page.name)
                                    view = model.active_view
                                    new_view = view.zoom_extents
                                    status = page.update(33) 
                                    }
                                
                                

                                But I have to press OK on the messagebox when scene-update has finished.

                                Edit: Kernel.sleep does not work for that.

                                1 Reply Last reply Reply Quote 0
                                • D Offline
                                  Dan Rathbun
                                  last edited by 17 Sept 2012, 14:44

                                  @hpw said:

                                  Edit: Kernel.sleep does not work for that.

                                  Yes.. I guess we decided it would not, because the C++ engine cannot call observers, as the scene changes, etc.

                                  I'm not here much anymore.

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  1 / 1
                                  • First post
                                    1/16
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement