child objects index position in hierarchy [SOLVED]

On 08/12/2014 at 08:18, xxxxxxxx wrote:

Is there a function to get a selected child objects index position in a parent hierarchy? For example, I have a cloner with three primitives as its children.

|_ **Cube  **(Index position would be 1)

I'm currently getting it with multiple steps and wasn't sure if there was something more efficient.

Right now I:

1. Get selected object.
2. Get the parent of the selected object.
3. Get the children of the parent object.
4. Get the index number by seeing if selected object in children (children.list(selected)).

I've tried searching the forum and Google, but I may not be searching the right keywords.


On 08/12/2014 at 08:45, xxxxxxxx wrote:


I don't think there is a dedicated function for such task. You could simply "go up" by checking the previous object until there is no previous object anymore. The number of steps would be your index.

  activeObject = doc.GetActiveObject()  
  pred = activeObject.GetPred()  
  count = 0  
  while pred:  
      count = count + 1   
      pred = pred.GetPred()  
  print count  

Best wishes,

On 08/12/2014 at 08:48, xxxxxxxx wrote:

That's a nice, clean approach.  Thanks for your help.