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!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Trying to sort scenes by alphabetical order..Need Help!

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 5 Posters 754 Views 5 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

      @renderiza said:

      So no need to put ";" ?

      only if more than 1 statement per line (like in the console.)

      Otherwise you just make your files larger, and make the interpreter read an extra character each line.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • renderizaR Offline
        renderiza
        last edited by

        Thanks that is good to know!

        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

        1 Reply Last reply Reply Quote 0
        • renderizaR Offline
          renderiza
          last edited by

          Hi, here is my progress so far...

          
          model = Sketchup.active_model 
          pages = model.pages 
          page_num = 0 
          org = pages.map{|pg| pg.name }.sort!
          num = pages.count 
          amount = 0 
          times = 0 
          
          begin
              pages.each { |page|
                  page.transition_time=0 
                  if page.name == "#{org[amount]}"
                      pages.selected_page = model.pages[page_num] 
                      break
                  end 
                  page_num+=1 
                            
              } #pages.each
          	
          page_num = 0 
          amount += 1 if amount < num
          
          pages.add "#{org[amount-1]}" 
          
          end while amount < num
          
          
          begin
          pages.selected_page = model.pages[0] 
          Sketchup.send_action(CMD_PAGE_DELETE)
          times += 1
          end while times < num
          

          The above code will reorganize your scenes by name. The only thing I wish it would change is if it didn't have to prompt a message before deleting unwanted scenes but other than that I am happy with results!

          If anyone have any suggestions in making my code fancier and better written please let me know.

          Again Thanks!

          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

          1 Reply Last reply Reply Quote 0
          • renderizaR Offline
            renderiza
            last edited by

            Hi,

            Here is little code sniped for renaming all scenes and add number...

            model = Sketchup.active_model 
            pages = model.pages 
            @page_name = "Name" 
            @page_num = 1 
            
            pages.each do |page| 
                page.name = "#{@page_name}#{@page_num}"
                @page_num = @page_num + 1
            end ;#Pages.each
            

            Cheers!

            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

              @renderiza said:

              The only thing I wish it would change is if it didn't have to prompt a message before deleting unwanted scenes but other than that I am happy with results!

              Instead of:

              pages.selected_page = model.pages[0] 
              Sketchup.send_action(CMD_PAGE_DELETE)
              

              use:

              my_page = model.pages[0] 
              model.pages.erase( my_page )
              

              That will delete the page without issuing a warning to the user.

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

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

                #You are over complicating it somewhat.
                #Also it's a bit clearer if you use {}, for the new 'sorted' pages:
                ` model = Sketchup.active_model
                pages = model.pages
                selpage = pages.selected_page.name
                opages = pages.map**{**[/b] |pg| pg.name }.sort
                num = opages.length

                opages.each**{** |page|
                optt = pages[page].transition_time #***
                pages[page].transition_time = 0

                fix delay_time too***

                opdt = pages[page].delay_time #***
                pages[page].delay_time = 0
                pages.selected_page = pages[page]
                newp = pages.add(page)
                newp.transition_time = optt
                newp.delay_time = opdt
                }#***Good idea to store the original page.transition_time& delay_timeetc and reapply them to the new page... #Then similarly for removing the unsorted pages use {}... num.times**{** pages.erase(model.pages[0]) }#to erase all of the original pages. #then to restore the originally selected page by name, add... pages.selected_page = pages[selpage]`
                πŸ˜„

                TIG

                1 Reply Last reply Reply Quote 0
                • renderizaR Offline
                  renderiza
                  last edited by

                  Thank you both very much!

                  This was the best feedback I could hope for! 😍

                  Cheers!

                  [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @renderiza said:

                    ... The only thing I wish it would change is if it didn't have to prompt a message before deleting unwanted scenes ...

                    replace:
                    Sketchup.send_action(CMD_PAGE_DELETE)

                    with:
                    pages.erase *some_page_object_ref*

                    πŸ’­

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • AdamBA Offline
                      AdamB
                      last edited by

                      Following this thread, I wonder whether the OP would be better off just caching each Scene in a convenient format and simply filling the existing Scenes as 'buckets' - rather than creating and destroying objects all the time.

                      So simply set attributes, names, camera etc etc for each.

                      Adam

                      Developer of LightUp Click for website

                      1 Reply Last reply Reply Quote 0
                      • renderizaR Offline
                        renderiza
                        last edited by

                        Hi,

                        I updated [Re]Scene to include the feature to reorganize all scenes by alphabetical order. Thanks for all the help!

                        New Web-Dialog:

                        http://s15.postimg.org/ycqlsebaj/dlg_1.jpg

                        Plugin Page: http://sketchucation.com/forums/viewtopic.php?f=323&t=52203

                        Cheers! πŸ‘

                        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                        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