sketchucation logo sketchucation
    • Login
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Getting and iterating scene list?

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 3 Posters 348 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      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
      • thomthomT Offline
        thomthom
        last edited by

        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
        • thomthomT Offline
          thomthom
          last edited by

          @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
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @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
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @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
              • thomthomT Offline
                thomthom
                last edited by

                @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
                • thomthomT Offline
                  thomthom
                  last edited by

                  @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
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    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
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @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
                      • thomthomT Offline
                        thomthom
                        last edited by

                        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

                          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

                            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
                            • Dan RathbunD Offline
                              Dan Rathbun
                              last edited by

                              @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
                              • First post
                                Last post
                              Buy SketchPlus
                              Buy SUbD
                              Buy WrapR
                              Buy eBook
                              Buy Modelur
                              Buy Vertex Tools
                              Buy SketchCuisine
                              Buy FormFonts

                              Advertisement