Trying to sort scenes by alphabetical order..Need Help!
-
Hi,
Thanks yet again!
@dan rathbun said:
PS: why are you putting ; at the end of each line ?
I though that was good practice
Keep in mind I never took a programming class in my life so I am very thankful for people steping in and pointing something that it shouldn't be done.
So no need to put ";" ?
@dan rathbun said:
BTW.. the API does not expose the moving of a page to a new location.
You have to clone the page (incl. all it's properties,) to the new location, and then delete the old page.
When you use
pages.add
the API uses the current selected page as the "mold".Yes I was thinking of doing what you just suggested.
Again Thanks a lot!
-
@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.
-
Thanks that is good to know!
-
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!
-
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!
-
@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.
-
#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.lengthopages.each**{** |page|
optt = pages[page].transition_time #***
pages[page].transition_time = 0fix 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]`
-
Thank you both very much!
This was the best feedback I could hope for!
Cheers!
-
@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*
-
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
-
Hi,
I updated [Re]Scene to include the feature to reorganize all scenes by alphabetical order. Thanks for all the help!
New Web-Dialog:
Plugin Page: http://sketchucation.com/forums/viewtopic.php?f=323&t=52203
Cheers!
Advertisement