• Login
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!
🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

Delete All Scenes with API Question...

Scheduled Pinned Locked Moved Developers' Forum
2 Posts 2 Posters 1.1k Views 2 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
    renderiza
    last edited by renderiza 3 Oct 2017, 14:23

    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.

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

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 3 Oct 2017, 14:37

      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.

      TIG

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      1 / 1
      • First post
        2/2
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement