# Retrieve all entities in a layer

**URL:** <https://forums.sketchup.com/t/retrieve-all-entities-in-a-layer/26377>\
**Category:** Ruby API\
**Created:** [June 12, 2016, 5:46pm UTC](https://forums.sketchup.com/t/retrieve-all-entities-in-a-layer/26377 "2016-06-12T17:46:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [June 12, 2016, 6:19pm UTC](https://forums.sketchup.com/t/retrieve-all-entities-in-a-layer/26377/2 "2016-06-12T18:19:51Z")

</div>

> [@twan](#):
>
> Could anyone show me how to retrieve all entities in a layer ?

**(1)** Layers in SketchUp do not own an entities collection. Layers in SketchUp are behavioral property objects that entities can share, in order to control color, visibility, etc.

**(2)** In SketchUp all primitives (edges, curves, arcs, circles and faces) need to be assigned to use “Layer0”. (So the implication is that filtering by “Layer0” will not do you much good.)

**(3)** Only groups, component instances (or Clines & Cpoints) should be assigned to use other layers.

**(4)** In the SketchUp API (and it’s Document Object Model,) it is not just the model that has an entities collection. All types of definitions (groups, images and components) also have entities collections.

There are examples here in this forum on how to search for groups or components by name. You can just as easily change the method call to check the layer name that an entity is assigned to use.

Basically something like:

```ruby
model = Sketchup::active_model
grps = model.entities.grep(Sketchup::Group)
grps_on_layer_twan = grps.find_all {|grp|
  grp.layer.name == "twan"
}

```

> [@twan](#):
>
> … and how to access properties of entities like location, width, height, …?

In geometry, objects have transformations. Component and Group instances have a **`transformation`** method that returns a [**`Geom::Transformation`**](http://www.sketchup.com/intl/en/developer/docs/ourdoc/transformation) instance.

```ruby
grps_on_layer_twan.each {|grp|
  puts "Group '#{grp.name}' located at: #{grp.transformation.origin.to_s}"
}

```

> [@twan](#):
>
> I am completely new to Sketchup.

Firstly, one must learn how the application works from the manual user’s point of view, before you can automate using the Ruby API.

Second, one must learn standard Ruby in order to apply the extensions that the SketchUp API adds to Ruby. See the [Ruby Learning Resources](http://forums.sketchup.com/t/ruby-learning-resources-wikilists/22861/9) “pinned post” here in this topic.

Then study the examples given on the API site, and [those by the SketchUp team](http://extensions.sketchup.com/en/content/example-ruby-scripts) downloadable from the Extension Warehouse.

Look at how other authors have written their extensions (if they are not scrambled.)

There are several threads in this category about how to begin learning SketchUp Ruby.

---

_[View the full topic](https://forums.sketchup.com/t/retrieve-all-entities-in-a-layer/26377)._
