Jump to content

Rename dozens of layers using a CSV file

Recommended Posts

Hello there, 


I'm pretty new to c4d and python scripting so I don't even know if what I want to do is possible in theory, though it sounds somewhat plausible.

I have an excel list with 300 names and need all of them as MoText Elements. As each MoText is combined with several other Elements, which are all under one Null, I thought about renaming the Nulls and using their name as a driver for the MoText-text.


Hierarchy of my c4d file:


->MoText (child of Null.1)

->Fancy-Element (child of Null.1)


->MoText (child of Null.2)

->Fancy-Element (child of Null.2)

and so on..


Example of my .csv file:



I want to use ".1(2,3 etc.)" as an indicator of which name to grab from the .csv file. Maybe there is a way to import the .csv as a string and be able to split it with the comma as a separator, so you can get access to each name individually and globally replace all Null-names.

Null.1 -> Dennis

Null.2 -> John

Null.3 -> Markus

and so on


is this possible and how complicated would it be to write a script for that?


Thanks in advance!



Link to post

Sure, this is possible and shouldn't be complicated.

There's really only this one line in the CSV?

And all you want is the Nulls renamed?

Wouldn't it be more efficient, to build the entire hierarchy based on the CSV?

Also it's always helpful to provide a scene for testing, when asking for scripts or alike. This can remove a lot of ambiguity and also spares the developer the need to setup her/his own scene (which the may already be a wrong basis and misleading).

Anyway, I'll be back...


Link to post

So, here you go as a starter.


The CSV file I used for testing:


My test scene:


The script for Script Manager:



And for discussion, the script itself:

# Rename Null objects based on information from a CSV file
import c4d


def main():
    filename = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, doc.GetDocumentPath(), c4d.FILESELECT_LOAD)
    if filename is None:

    # Get names as array from CSV file
    fileCsv = None
    names = []
        # Read CSV file
        fileCsv = open(filename.decode("utf-8"), mode='r')
        # TODO Currently only reading first line, only (based on forum post)
        names = fileCsv.readline().split(SEPARATOR)
        if fileCsv is not None:

    # Rename Null objects
    obj = doc.GetFirstObject() # TODO only searching top-level of object hierarchy for Nulls to rename
    while obj is not None:
        if obj.CheckType(c4d.Onull):
            nameParts = obj.GetName().rsplit(NAME_INDEX_SEPARATOR)
            if len(nameParts) > 1 and nameParts[1].isdigit() and nameParts[0] == 'Null' and \
               int(nameParts[1]) >= 0 and int(nameParts[1]) < len(names):
                doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
        obj = obj.GetNext()

if __name__=='__main__':



Edited by MighT
removed debug print
Link to post


@MighT Thank you so much for taking the time to write this script! It is exactly what I needed. Worked like a charm. How did you get into coding for C4D? I learned a little bit of python on codecademy but there is so many things here exclusive to C4D. I'd love to be able to write things like this on my own (Or at least be able to extend it to the case where there is a first Null without a digit, which I've tried without success.). Do you have any advice for me? 

Thanks again!


Link to post

You are welcome, glad it helped.


Well, C4D has always been a hobby of mine since its Amiga times. Really just a hobby. I was fascinated by computer generated imagery and simulated physics. Yet, have never been able to produce anything anybody with a clear conscious would call art, because... probably because my brain doesn't work this way. I studied electrical engineering and worked as a system design engineer for almost 15 years (mainly C and VHDL programming). Around that time I decided to shift my focus onto something I like better and to try to hire at MAXON. Therefore I thought, it wouldn't hurt to have developed a plugin before. I took my year's vacation, MAXON's SDK documentation and the SDK examples and worked myself into it. Not that it helped with getting hired by MAXON (it took three more years to get into there), but for a reasonably experienced developer it was certainly possible to learn enough to get three plugins working (of which I released only two to the public and their functionality got redundant with MAXON's next major releases...). Only after I got hired by MAXON and worked inside the SDK Team I then also started familiarizing with the Python side.
I doubt, you wanted to hear my life's story, but at least that's how I got into developing plugins. And you asked how I got into plugin development...


Please, don't get me wrong, I certainly do not want to say, you need to study programming to get into it. Far from it. Actually I think it's more important to understand certain principles of C4D. Then, if you are able to program in Python, the SDK documentation and examples should get you going quite a bit. And finally, I think MAXON is quite generous in this regard, there's MAXON's SDK Team (and I'm not mentioning this, because I was in there) who provide free support to everybody in the Plugin Cafe forum. These guys usually get your problems solved quite quickly and nicely.


Nowadays there are also other nice resources. Did you see @Cairyn's  spoonfed series? Recommended. The links somewhere here in the forum. If you are planning to reach an age of 150, you may also wait for me to release my long planned YT tutorials on C4D Python development. Unfortunately there's too much in the pipe to get to these. 


Last note: I do also teach C++ and/or Python plugin programming for C4D to interested people (and also to not interested people who are forced by their boss to do it nevertheless). Maybe you are interested. While I usually do not do this for free, it is on a pay-what-you-want,-are-able-to-afford-and-deem-worthy basis. No strings attached. PM me, if you are interested. If enough people in here are interested, we can also do a Q&A chat session.


Link to post

Ah, I missed your question on the first Null without digit. Actually that's why it's always good to post a scene 😉

How are the Nulls to be renamed identified? All Nulls on the topmost hierarchy level? Or just Nulls which begin with Null?

I assumed it to be potentially dangerous, if the script simply renamed all Nulls, so I deliberately made it so that it only renames those named like this "Null.n" (with n a number).

How is the logic then? If there is only "Null" it will be the name with index zero?


Link to post

Here, with this change it will rename all Null objects which name starts with "Null". If there's a numeric suffix and the index can be found in the name list, the respective name is used, in all other cases the first name (index zero) is used.


Here, it's only the renaming section. Simply replace the block with this one:

    # Rename Null objects
    obj = doc.GetFirstObject() # TODO only searching top-level of object hierarchy for Nulls to rename
    while obj is not None:
        if obj.CheckType(c4d.Onull):
            nameParts = obj.GetName().rsplit(NAME_INDEX_SEPARATOR)
            if nameParts[0] == 'Null':
                doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
                if len(nameParts) > 1 and nameParts[1].isdigit() and \
                    int(nameParts[1]) >= 0 and int(nameParts[1]) < len(names):
        obj = obj.GetNext()


Link to post

Sir, I can't thank you enough for taking the time to write all this. Not only for completing the code and creating a very useful script for all of us, but also for explaining to me how you got into coding and what's the best approach for someone new to the game like me. In fact I kind of was interested in your lifestory, so thanks for sharing it! Feels good to get help from someone working at MAXON, they seem like a very user-connected company. As for my Part, I am probably going to take a look at Cairyn's Spoonfed Series as a first step and also just play around with the examples in the SDK documentation. If I feel like there is a chance for me to seriously get into python more and my mograph carreer allows me to do so, you'll be the first one I'll get in touch with. You definitely seem like you know what you're doing and I'd be happy to pay for your services once I am more committed.


Thank you so much again for your time



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.

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.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...