💡 LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
Delete All Scenes with API Question...
-
Hi,
Why the following code only deletes some scenes and not all?
model = Sketchup.active_model pages = model.pages pages.each {|page| pages.erase(page)}
A workaround for this issue is...
model = Sketchup.active_model pages = model.pages delete_list = [] pages.each {|page| delete_list << page} delete_list.each {|page| pages.erase(page)}
But still, I ask why did the first example fail to deliver?
Shortly after this I post stumbled upon this TOPIC and it explained the issue.
-
When you iterate a collection - like pages, or selection or entities, and change that collection's contents - e.g. by deleting something - then you get issues because the collection changes as a result.
BUT if you 'freeze' the collection, but using.to_a
OR perhaps you collect items, which are then deleted afterwards, after you exit using the collection... then it avoids the issue.
Advertisement