Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    child objects index position in hierarchy [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 379 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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.

      Cloner
      |_Sphere
      |_ **Cube  **(Index position would be 1)
      |_Torus

      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.

      Thanks

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        Hello,

        I don't think there is a dedicated function for such task. You could simply "go up" by checking the previous object[URL-REMOVED] 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,
        Sebastian


        [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post