# Test for how many objects in heirarchy?

**URL:** https://forum.highend3d.com/t/test-for-how-many-objects-in-heirarchy/747
**Category:** Maya
**Tags:** mel
**Created:** [April 14, 2010, 6:15pm UTC](https://forum.highend3d.com/t/test-for-how-many-objects-in-heirarchy/747 "2010-04-14T18:15:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![legendarylugi](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/l/3d9bf3/32.png) [@legendarylugi](https://forum.highend3d.com/u/legendarylugi)
#### Post date: [April 14, 2010, 6:15pm UTC](https://forum.highend3d.com/t/test-for-how-many-objects-in-heirarchy/747/1 "2010-04-14T18:15:08Z")

</div>

I'm pretty new to MEL scripting, but I was wondering if there is some sort of command that can return the number of children an object or group has, because the script I'm writing needs to reference that value. Any help you can provide would be greatly appreciated.

---

<div class="post-metadata">

### Author: ![thnkr](https://forum.highend3d.com/user_avatar/forum.highend3d.com/thnkr/32/115_2.png) [@thnkr](https://forum.highend3d.com/u/thnkr)
#### Post date: [April 14, 2010, 6:34pm UTC](https://forum.highend3d.com/t/test-for-how-many-objects-in-heirarchy/747/2 "2010-04-14T18:34:49Z")

</div>

&nbsp;size `listRelatives -allDescendents`;

---

<div class="post-metadata">

### Author: ![legendarylugi](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/l/3d9bf3/32.png) [@legendarylugi](https://forum.highend3d.com/u/legendarylugi)
#### Post date: [April 14, 2010, 6:40pm UTC](https://forum.highend3d.com/t/test-for-how-many-objects-in-heirarchy/747/3 "2010-04-14T18:40:32Z")

</div>

thanks a million. =) I'll test that out when I next work on the script.

---

<div class="post-metadata">

### Author: ![legendarylugi](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/l/3d9bf3/32.png) [@legendarylugi](https://forum.highend3d.com/u/legendarylugi)
#### Post date: [April 15, 2010, 7:39pm UTC](https://forum.highend3d.com/t/test-for-how-many-objects-in-heirarchy/747/4 "2010-04-15T19:39:13Z")

</div>

Hmmm, two things (one's a problem, one's not): When I run the command, the number it returns is 114, but I know in this particular case it's 57 (half the number). Is it returning the shape and transform nodes of each object or something? Not really a problem, since I can just divide the number in half for my purposes, just curious what it's doing under the hood.

Secondly, how can I store the result in a variable? Rather than simply setting the value of the variable based on what I know, how can I make it grab the result and store it automatically?

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [April 16, 2010, 6:41am UTC](https://forum.highend3d.com/t/test-for-how-many-objects-in-heirarchy/747/5 "2010-04-16T06:41:57Z")

</div>

Shapes are part of the equation yes.

You can use ls to filter the list so it only transforms or whatever type you wish. Its safer than assuming theres 1 shape under each transform.

$var=size( ls("-transforms", listRelatives("-allDescendents")) );

Pretty basic syntax stuff.
