# Finding active section planes in a scene

**URL:** <https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161>\
**Category:** Ruby API\
**Created:** [October 13, 2016, 9:25pm UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161 "2016-10-13T21:25:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris.bassett25](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/chris.bassett25/32/23427_2.png) [@chris.bassett25](https://forums.sketchup.com/u/chris.bassett25)\
**Post date:** [October 13, 2016, 9:25pm UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/1 "2016-10-13T21:25:26Z")

</div>

Hi Folks,

I’m writing a script to delete unused section planes as an aid to working with large models and drawing sets

I’ve so far been able to get a script to work by walking through the scenes via the pages.selected\_page method and using an if loop to find the section planes to delete.

Its is possible to determine if a section plane is active in a scene directly. Ideally, I would not like to activate every scene?

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [October 13, 2016, 11:36pm UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/2 "2016-10-13T23:36:46Z")

</div>

It’s often useful to post the code you have, and an example skp…

people short on time are more likely to test yours and modify if they know [or suspect] a solution…

john

---

<div class="post-metadata">

**Author:** ![chris.bassett25](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/chris.bassett25/32/23427_2.png) [@chris.bassett25](https://forums.sketchup.com/u/chris.bassett25)\
**Post date:** [October 14, 2016, 2:47am UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/3 "2016-10-14T02:47:23Z")

</div>

I’m on my tablet so I’ll do the best I can.

I’m currently doing something like this puesdo code.  
Getting it to work is not the issue. I’m wondering if there’s a cleaner way to do it.

* * *

```auto
#make a list of section planes to delete later
Pages = SketchUp.model.pages 
List = grep(SketchUp::section_planes)

#walk through and activate each scene
Pages.each { |page| 
     Pages.selected_page = page

          #iterate through list of planes, remove from list if    
          #active
          List.each { |section_plane|
               If section_planes.active?
                    List.delete.section_plane
               End
          }
}

#delete whatever is left in the list array
List.each { |section_plane| 
     section_plane.erase!
}

```

* * *

Activating the scenes is really slow if animations are turned on. It’s not a huge deal to turn them off. That said I’d like to query the API about what is active in each scene without activating the scene. I’ve run into a roadblock here and am wondering if there is any insight.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [October 14, 2016, 4:38am UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/4 "2016-10-14T04:38:22Z")

</div>

> [@chris.bassett25](#):
>
> List = grep(SketchUp::section\_planes)

I will assume that your tablet is capitalizing all lines.  
Variables should not be constants. (In Ruby constants begin with a capital letter.)

* * *

**(1)** So, you cannot call [**`Enumerable#grep()`**](http://ruby-doc.org/core-2.0.0/Enumerable.html#method-i-grep) upon nothing. It must be called upon a collection object whose class has mixed in the [**`Enumerable`**](http://ruby-doc.org/core-2.0.0/Enumerable.html) library module.

**(2)** There is no **master** collection of just [**`Sketchup::SectionPlane`**](http://ruby.sketchup.com/Sketchup/SectionPlane.html) instance objects. They are a [**`Sketchup::Drawingelement`**](http://ruby.sketchup.com/Sketchup/Drawingelement.html) subclass, and as this they can be a member of any [**`Entities`**](http://ruby.sketchup.com/Sketchup/Entities.html) collection. This means either the model’s top level collection of entities, or of the entities collection of [definitions](http://ruby.sketchup.com/Sketchup/ComponentDefinition.html) (as images, groups and component instances do not themselves “own” entities.)

So, **a.** , either iterate the [DefinitionsList](http://ruby.sketchup.com/Sketchup/DefinitionList.html) collecting the section planes,…

```ruby
cutplanes = model.entities.grep(Sketchup::SectionPlane)
model.definitions.each {|cdef| 
  cutplanes.concat( cdef.entities.grep(Sketchup::SectionPlane) )
}

```

or **b.** , collect all section planes in the ObjectSpace, and filter out those that do not belong to the active model:

```ruby
cutplanes = []
ObjectSpace.each_object(Sketchup::SectionPlane) {|obj|
  cutplanes << obj if obj.model == Sketchup::active_model
}

```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [October 14, 2016, 9:05am UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/5 "2016-10-14T09:05:25Z")

</div>

> [@chris.bassett25](#):
>
> I’m writing a script to delete unused section planes as an aid to working with large models and drawing sets

The concept of active and used are different. Just because a section plane is not active at any given time, does not mean it is unused.

You have already noted that scene pages can switch planes on and off, and you’ve handled that well by first keeping any section plane that is activated by scene changes.

But section planes can also be activated by extensions, or created manually for use in a single “Work” scene. Your example would brute force remove these.

Perhaps present the user with a list of Section Planes to confirm deletion ? (We have requested that they get a “name” attribute.)

… or, one by one, show and select the section plane, zoom to selection, then ask the user whether to delete the shown plane ?

---

<div class="post-metadata">

**Author:** ![chris.bassett25](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/chris.bassett25/32/23427_2.png) [@chris.bassett25](https://forums.sketchup.com/u/chris.bassett25)\
**Post date:** [October 14, 2016, 3:18pm UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/6 "2016-10-14T15:18:57Z")

</div>

confusion is what I get for trying to write code on a tablet after a long mountain bike ride…

I had meant to say I had a working code similar to the “code” I typed in. What I stumped on, is finding away to search for active section planes without activating the scene. Any thoughts?

I agree with you from your above post. In this case, the simplicity is fine for me, I’ll sometimes have to deal with a model that looks like a sea of gray and just want it gone. In my particular case, I very infrequently work with extensions that use section planes and would know when to be careful.

Below is my working code.

> ```
> #make a list of section planes to delete later
> pages = Sketchup.active_model.pages 
> entities = Sketchup.active_model.entities
> list = entities.grep(Sketchup::SectionPlane)
> 
> ```

> ```
> #walk through and activate each scene
> pages.each { |page| 
> pages.selected_page = page
> 
> ```

> ```
> #iterate through list of planes, remove from list if    
> #active
> list.each { |section_plane|
> if section_plane.active? == true
> list.delete(section_plane)
> end
> }
> }
> 
> ```

> ```
> #delete whatever is left in the list array
> list.each { |section_plane| 
> section_plane.erase!
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [October 15, 2016, 1:44am UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/7 "2016-10-15T01:44:15Z")

</div>

Your code ignores section planes inside groups and components.

> [@chris.bassett25](#):
>
> What I stumped on, is finding away to search for active section planes without activating the scene. Any thoughts?

Catch-22. The plane cannot be active until the scene is set as the current view.

You may also need to implement a [**`FrameChangeObserver`**](http://ruby.sketchup.com/Sketchup/Pages.html#add_frame_change_observer-class_method), to delay the active? test until the scene is done rendering.

Also, what I usually do in cases like this is switch page transitions off (saving the old value and restoring it afterward.)

```ruby
model = Sketchup::active_model
prev = model.options["PageOptions"]["ShowTransition"]
model.options["PageOptions"]["ShowTransition"]= false

```

afterward:

```ruby
model.options["PageOptions"]["ShowTransition"]= prev

```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [October 8, 2025, 2:01pm UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/8 "2025-10-08T14:01:27Z")

</div>

> [@chris.bassett25](#):
>
> What I stumped on, is finding away to search for active section planes without activating the scene.

**Good news** , SketchUp **2026.0** has implemented:

- [`Sketchup::Page#active_section_planes()`](https://ruby.sketchup.com/Sketchup/Page.html#active_section_planes-instance_method)

So **going forward** we no longer need to transition to a page (or each page) to find which of the section planes are active.

* * *

With regard to API tracker issue # 25  
[See what scenes a section is used in · Issue #25 · SketchUp/api-issue-tracker](https://github.com/SketchUp/api-issue-tracker/issues/25)

```ruby
# See what scene pages where a section is active. (SU2026+)
#
# @return [Array<Sketchup::Page>] The list of scene pages that the given
# SectionPlane is active on, or empty if the section is unused on any page.
def pages_active_on(section)
  unless section.is_a?(Sketchup::SectionPlane)
    fail(TypeError,"SectionPlane expected for <#{section.class}> argument.",caller)
  end
  section.model.pages.select do |page|
    page.active_section_planes.include?(section)
  end
end

```

@ene_su **Does this snippet now satisfy tracker issue #25 ?**  
I.e., using `page.active_section_planes.include?(section)` within a `select` filter block upon the `pages` collection.

# 

* * *

> [@chris.bassett25](#):
>
> I’m writing a script to delete unused section planes as an aid to working with large models and drawing sets.

And in keeping with this new API feature, the SketchUp Extensibility Team has released an Example extension to purge unused section planes. (requires SketchUp 2026 or higher.)

See:

> [@Purge Unused Section Planes](https://forums.sketchup.com/t/purge-unused-section-planes/340816):
>
> New team extension is out today partying_face This extension lets you remove section planes not currently used by a scene. This allows you to quickly remove any temporary section planes you use to see what you are working on, without risking losing section planes carefully set up for use in Layout to generate drawings. This extension also serves as a code example for the new scene section plane API released in SketchUp 2026.0. SketchUp 2026.0 required.

---

<div class="post-metadata">

**Author:** ![bmike](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/bmike/32/225451_2.png) [@bmike](https://forums.sketchup.com/u/bmike)\
**Post date:** [October 8, 2025, 2:59pm UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/9 "2025-10-08T14:59:34Z")

</div>

> [@DanRathbun](#):
>
> And in keeping with this new API feature, the SketchUp Extensibility Team has released an Example extension to purge **unused scene pages**.

Not sure that is what the new extension does.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [October 8, 2025, 3:09pm UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/10 "2025-10-08T15:09:23Z")

</div>

[The quoted post has brain glitch corrected.]

---

<div class="post-metadata">

**Author:** ![ene\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/ene_su/32/103091_2.png) [@ene\_su](https://forums.sketchup.com/u/ene_su)\
**Post date:** [October 8, 2025, 3:43pm UTC](https://forums.sketchup.com/t/finding-active-section-planes-in-a-scene/32161/11 "2025-10-08T15:43:38Z")

</div>

Issue #25 is implemented with SketchUp 2026 🥳.

However we haven’t gotten to the release task of closing the finished issues on GitHub yet
