CINEVERSITY

    Maxon Logo
    • Login
    • Search
    • Recent
    • Popular
    • Users
    • Groups

    Rename Children of selected objects

    Cinema 4D Assets & Plugins
    2
    2
    473
    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.
    • T
      truth-dream last edited by truth-dream

      With this script you can rename the children a null object, or any selection that has children inside, to match the parent's name + an incremental number, use in python scripts inside cinema. You can select any number of objects and it will rename the objects inside each parent to it's parent's name.

      This is very useful when importing AI layers that have many paths inside.

      import c4d
      
      def main():
          # Get the active objects
          active_objects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
      
          # Loop through each active object
          for obj in active_objects:
              # Get the name of the object
              base_name = obj.GetName()
      
              # Get the children of the object
              children = obj.GetChildren()
      
              # Loop through each child
              for i, child in enumerate(children):
                  # Rename the child with the base name and an incremental number
                  child.SetName(f"{base_name}_{i+1}")
      
          # Update the Cinema 4D scene
          c4d.EventAdd()
      
      # Execute main()
      if __name__=='__main__':
          main()
      
      
      1 Reply Last reply Reply Quote
      • Dr. Sassi
        Dr. Sassi last edited by

        Hi truth-dream,

        The idea of this forum is about the content provided by Maxon.

        Please check programming suggestions or questions in the Developer-Café.
        https://plugincafe.maxon.net/
        This is the correct place for it.

        I feel somewhat uncomfortable having code here, in general, for various reasons.
        The moderator of the Plugin Café is better suited for this.

        All the best

        Dr. Sassi Sassmannshausen Ph.D.
        Senior Trainer, Maxon Master Trainer, L&D - Strategist
        Cinema 4D mentor since 2004, Member of VES, DCS.

        1 Reply Last reply Reply Quote
        • First post
          Last post