Jump to content

Sign in to follow this  
phildoooo

Renaming in hierarchy (Python)

Recommended Posts

Hi there, I'm Phil

 

Decided to take the dive and try learning some Python (primarily for C4D) whilst work is quiet.  Do you guys have any suggestion for learning materials? I managed to get my first script running to simply rename some objects... cant work out how to paste the whole code here 😕

 

My next task is much more complicated. I was thinking about trying to create a script to help naming joints for rigging... Firstly I think what I need to do is:

 

create a list of all children and grandchildren etc. for the selected object (dont know if i use something like GeListNode.GetChildren?)

go through the list naming in hierarchy. potentially like:

      l_bn_01

                       l_bn_01_a

                                             l_bn_01_a_01                     

                       l_bn_01_b

                                             l_bn_01_b_01

                                             l_bn_01_b_02

 

if that makes sense. I'm pretty sure this is not a simple task, but if someone can get me started in the right direction that would be awesome. Hope I can at least make a loop to GetNext object in the hierarchy for renaming.

Edited by Cerbera
Retitled for search accuracy

Share this post


Link to post

@Cairyncan you help? 🙂 


| MAXON Quality Assurance Specialist | 3D Asset Creator | C4D Cafe Manager |

Share this post


Link to post

@phildoooo

RE:  cant work out how to paste the whole code her
Uhm. Just copy and paste it? There's also a code icon in the post panel UI that allows you to format the code. 

RE: go through the list naming in hierarchy
Luckily for you, there is already an existing resource for down. 
This should cover majority of what you need.
https://www.curiousanimal.tv/blog/c4d-python-snippet-navigating-hierarchy/

Also. "Python. Hi Am New" is not a helpful title. 
Please rename it. 

Good luck.

Share this post


Link to post

Traversing the tree (or just the joints, respectively) has been covered in my Python: Spoodfed course (hopefully exhaustively 😁)

 

The iterative tree traversal was discussed here (and in adjacent chapters):

https://www.patreon.com/posts/python-spoonfed-30982663

 

This chapter is referring to joints and the walking through joint structures specifically:

https://www.patreon.com/posts/python-spoonfed-31813681

 

And here is a bit on recursion and recursive tree walking, which you may need to create the desired name schema:

https://www.patreon.com/posts/python-spoonfed-31995114

 

Note: while this is a Patreon, these chapters are all public, so feel free to browse.

Share this post


Link to post
  • Topic Author
  • @bentraje Thanks! I did stumble upon this during my research but wasn't entirely sure it's what I needed. I'll work my way through it now!

    strange that in my reply I am able to paste the code, but upon creating the post it would just paste 1 line in a white box. no big deal though.

     

    @Cairyn Thank you too! will check them out 😄 

    Share this post


    Link to post

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×
    ×
    • Create New...