# Finding all RShape children recursively (Geomerative)

**URL:** <https://discourse.processing.org/t/finding-all-rshape-children-recursively-geomerative/10241>\
**Category:** Libraries\
**Created:** [April 13, 2019, 5:35pm UTC](https://discourse.processing.org/t/finding-all-rshape-children-recursively-geomerative/10241 "2019-04-13T17:35:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![cdaein](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@cdaein](https://discourse.processing.org/u/cdaein)\
**Post date:** [April 13, 2019, 7:02pm UTC](https://discourse.processing.org/t/finding-all-rshape-children-recursively-geomerative/10241/2 "2019-04-13T19:02:33Z")

</div>

Tried a few different things and came up with this function:

```auto
RShape[] getAllChildren(RShape shp) {
  ArrayList<RShape> result = new ArrayList<RShape>();
  int numChildren = shp.countChildren();
  if (numChildren != 0) {
    for (int i = 0; i < numChildren; i++) {
      RShape[] children = getAllChildren(shp.children[i]);
      for (int j = 0; j < children.length; j++) {
        result.add(children[j]);
      }
    }
  } else {
    result.add(shp);
  }
  return result.toArray(new RShape[result.size()]);
}

```

I did a few tests and it seems working but if anyone has a better solution, please let me know!

---

_[View the full topic](https://discourse.processing.org/t/finding-all-rshape-children-recursively-geomerative/10241)._
