Pages.erase
-
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?
-
It's probably the indexed being shifted around when you delete the pages.
-
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.
-
you are iterating through the pages object with
pages.each
. And then on each loop, you are deleting an element from the pages object withpages.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
-
Of course thom beat me to it - twice!
Interseting, it does leave the bar behind....
Chris
-
-
@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. -
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 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.
-
@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...
-
Cheers guys, that makes sense
Advertisement