# Is there a way to select Scene by its name and access sectionplane tribute/entities?

**URL:** <https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383>\
**Category:** Ruby API\
**Created:** [August 20, 2019, 9:50pm UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383 "2019-08-20T21:50:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ychen182](https://avatars.discourse-cdn.com/v4/letter/y/dfb087/32.png) [@ychen182](https://forums.sketchup.com/u/ychen182)\
**Post date:** [August 20, 2019, 9:50pm UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383/1 "2019-08-20T21:50:52Z")

</div>

Hi, I just created 4 Scene and named them as Scene 1 to 4. And also created 4 cube model as group. Each one of the cube has a sectionplane to hide or show them. I tried to use the command

entities = Sketchup.active\_model.entities  
all\_groups = entities.grep(Sketchup::SectionPlane)

but Ruby gives me a blank array as: Ruby Code Editor: Ruby says:

When I tried the same thing as entities.grep(Sketchup::Scene). Ruby says: uninitialized constant Sketchup::Scene

---

<div class="post-metadata">

**Author:** ![ychen182](https://avatars.discourse-cdn.com/v4/letter/y/dfb087/32.png) [@ychen182](https://forums.sketchup.com/u/ychen182)\
**Post date:** [August 20, 2019, 9:53pm UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383/2 "2019-08-20T21:53:18Z")

</div>

Is there a way to select Scene by its name and modify the section plane as Active or not? I wish there would be a way to change sectionPlane value to be active or nil in different 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:** [August 20, 2019, 10:09pm UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383/3 "2019-08-20T22:09:51Z")

</div>

```ruby
model.pages.map(&:name)

```

---

<div class="post-metadata">

**Author:** ![ychen182](https://avatars.discourse-cdn.com/v4/letter/y/dfb087/32.png) [@ychen182](https://forums.sketchup.com/u/ychen182)\
**Post date:** [August 20, 2019, 10:54pm UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383/5 "2019-08-20T22:54:40Z")

</div>

Hi, I tried the command

model = Sketchup.active\_model # Open model  
model.pages.map(&:001)  
but console gives me this apply:

Ruby says: Nil result (no result returned or run failed)

even though I have created a Scene renamed as “001”

---

<div class="post-metadata">

**Author:** ![sdmitch](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/sdmitch/32/31265_2.png) [@sdmitch](https://forums.sketchup.com/u/sdmitch)\
**Post date:** [August 20, 2019, 11:36pm UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383/6 "2019-08-20T23:36:50Z")

</div>

Sketchup.active\_model.pages.selected\_page=Sketchup.active\_model.pages[“001”]

---

<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:** [August 20, 2019, 11:55pm UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383/7 "2019-08-20T23:55:58Z")

</div>

that code gives you all the names from the array of model pages…

it also gives a clue on where to **look** in the API \>\> [[**Pages**](http://ruby.sketchup.com/Sketchup/Pages.html)]…

```ruby
page_names = model.pages.map(&:name)

page_name = model.pages['001'] # => returns a reference to the page

```

john

---

<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:** [August 21, 2019, 2:11am UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383/8 "2019-08-21T02:11:00Z")

</div>

> [@ychen182](#):
>
> When I tried the same thing as `entities.grep(Sketchup::Scene)`  
> Ruby says: uninitialized constant `Sketchup::Scene`

Before the GUI called them “Scenes” they were first known as “Pages”.  
They got renamed “Scenes” in the GUI, but still retained the old classname in the API.

* * *

> [@ychen182](#):
>
> I tried to use the command
> 
> ```ruby
> entities = Sketchup.active_model.entities
> all_groups = entities.grep(Sketchup::SectionPlane)
> 
> ```
> 
> but Ruby gives me a blank array

Because you grepped the **model’s** `entities` collection which does not have any section planes.  
So the empty array was the correct result from the `grep` call.

To get a hash of the scene pages from each cube group …

```ruby
entities = Sketchup.active_model.entities
all_groups = entities.grep(Sketchup::Group)
section_planes = {}
all_groups.each { |grp|
  section_planes[grp.name]= grp.entities.active_section_plane
}

```

Now `section_planes` is a [hash](https://ruby-doc.org/core-2.5.1/Hash.html) with group names as the **keys** and active section plane references as the **values**.

---

<div class="post-metadata">

**Author:** ![Aerilius](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Aerilius](https://forums.sketchup.com/u/Aerilius)\
**Post date:** [August 21, 2019, 6:38am UTC](https://forums.sketchup.com/t/is-there-a-way-to-select-scene-by-its-name-and-access-sectionplane-tribute-entities/101383/9 "2019-08-21T06:38:10Z")

</div>

> [@ychen182](#):
>
> model = Sketchup.active\_model # Open model  
> model.pages.map(&:001)

When you get an error, you should always take a look at the error message:

```auto
SyntaxError: (eval):2: syntax error, unexpected tINTEGER, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
model.pages.map(&:001)
                     ^

```

which points to the token `&:001` which has incorrect syntax. Then you look up the [documentation of `map`](https://ruby-doc.org/core-2.2.4/Enumerable.html#method-i-map) and find that its normal (not shortened) usage is like:

```auto
collection.map{ |a_single_page|
  a_single_page.method_to_call()
}

```

(which is often shortened to `collection.map(&:method_to_call)`)  
As method name you used `001` which is not a valid name for Ruby methods.
