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

    Pages.erase

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

      using this: model.pages.each{|e| model.pages.erase(e)} to try and delete all the scenes in a file but it seems to only remove every other scene.

      e.g. If we started with scenes 1-6, it gets rid of 1,3,5, then if i run it again it gets rid of 2 and 6 and if i run it once more scene 4 is the last to go.

      Am i doing something silly or is it a bug?

      http://remusrendering.wordpress.com/

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

        It's probably the indexed being shifted around when you delete the pages.

        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

          Just tried it, if you convert the pages collection to an array first it works.
          Sketchup.active_model.pages.to_a.each { |p| Sketchup.active_model.pages.erase(p) }

          But doing so, the bar where the tabs used to be is still there, even though it's empty. It should disappear.


          pages.png

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

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            you are iterating through the pages object with pages.each. And then on each loop, you are deleting an element from the pages object with pages.erase( e ). So deleting objects from the collection you are iterating over will cause problems like that.

            Instead of iterating over the pages object, turn it into an array of page objects. So just change your code to this:

            model.pages.***to_a***.each{|e| model.pages.erase(e)}

            Then you are iterating over an array and erasing from the page object. So you are working on two separate objects, and avoiding any clashes.

            Did that make any sense?

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • Chris FullmerC Offline
              Chris Fullmer
              last edited by

              Of course thom beat me to it - twice!

              Interseting, it does leave the bar behind....

              Chris

              Lately you've been tan, suspicious for the winter.
              All my Plugins I've written

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

                @chris fullmer said:

                Of course thom beat me to it - twice!

                Where's the point and make fun smiley..?

                @chris fullmer said:

                Interseting, it does leave the bar behind....

                I filed a bug report on this.
                Would be nice if we found a workaround to force the bar to refresh and disappear though...

                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

                  @chris fullmer said:

                  you are iterating through the pages object with pages.each. And then on each loop, you are deleting an element from the pages object with pages.erase( e ). So deleting objects from the collection you are iterating over will cause problems like that.

                  Is this a Ruby bug? It's somewhat unexpected. I'd expect the .each to be able to keep track of the content it iterates.

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

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

                    On a PC only, if you add this line before erasing the scene-tabs it will toggles their bar's visibility - if they are off it will switch the bar on though...

                    Sketchup.send_action 10534
                    

                    TIG

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

                      @tig said:

                      On a PC only, if you add this line before erasing the scene-tabs it will toggles their bar's visibility - if they are off it will switch the bar on though...

                      Sketchup.send_action 10534
                      

                      With the unfortunate side-effect that when you later adds pages they are still hidden. 😕

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

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

                        @thomthom said:

                        @tig said:

                        On a PC only, if you add this line before erasing the scene-tabs it will toggles their bar's visibility - if they are off it will switch the bar on though...

                        Sketchup.send_action 10534
                        

                        With the unfortunate side-effect that when you later adds pages they are still hidden. 😕

                        BUT the View menu does allow you to switch them back to being visible... 😉

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          remus
                          last edited by

                          Cheers guys, that makes sense 👍

                          http://remusrendering.wordpress.com/

                          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