Cinema 4D OBJ Sequence

Cinema 4D .OBJ Sequence Export (Python Script, No Plug-ins)

As of Cinema 4D R17, there’s still no easy, built in method to export an OBJ sequence.

I needed a sequence made up of 1200 individual files to bring into Element 3D for After Effects.

There are two plugins that I’ve found that export a sequence of OBJ files, but neither of those were working as I needed them to for a recent project.

  • Riptide Pro ($50) partly worked, but for some reason – no matter what options I set in the plugin – it had an issue with some of the cloner objects that were scaled – they were coming into Element 3D at completely the wrong size and the scale animation was been completely ignored. Even when I baked the whole MoGraph simulation to keyframes (using NitroBake) it wasn’t working as I needed it to.
  • Plexus OBJ Sequence Exporter for C4D (free) exported the bare bones of the animation (including the scaled elements) correctly and if I’d been using Plexus, it would have been (appropriately) perfect . BUT, the Plexus OBJ Sequence Exporter doesn’t include any material ID’s in it’s OBJ files, and Element 3D requires each separate object to have a unique material applied if you want to texture them differently in Element 3D’s interface and generally have much more control over how you render with it in After Effects.

Exporting a single OBJ using Cinema 4D’s built exporter – File > Export... > Wavefront OBJ (*.obj) – created exactly the file I needed – it worked exactly as expected in Element 3D.  But there’s no option to export a sequence, just a single OBJ of whatever’s on screen at the time – and I didn’t fancy manually exporting 1200 frames.

At this point I was nearly ready to just render the entire video in Cinema 4D and forget Element 3D altogether, but I wasn’t quite ready to give up and needed the render speed and extra control I could get in After Effects.

After some more Googling, I eventually found exactly what I needed – an amazing little Python script by Owen Lim, hidden away on his Behance profile.

If you use version R16 of Cinema 4D or below, the script Owen has written should work perfectly for you as it is on his Behance page.

If you have R17 Owen’s script won’t work unless you make a few tweaks. So after even more googling, I found the changes I needed to make and managed to get it 100% working, which is what you see below.That was all a really long winded introduction to this incredibly useful script pasted below, updated to work in C4D R17.

 

Note:
I’ve only used this script in C4D on Windows 10, but it should hopefully work on the Mac version too.

 

 

The Script


EDIT: I’ve replaced the code that was written here with this link instead. The tab/indenting in the code |I had was wrong, and Python is apparently very picky when it comes to incorrect indentation and white-space.

Click the link below to view the code, or right-click it to save the file which you can then open in the Script Manager.
 
 
DOWNLOAD: C4D to OBJ.py
 
 


 

How to use it

To run the script, open up – Script > Script Manager – paste in the code or open the file in the link above, set the animation range and frame-rate, then click Execute.

 

Final Tip

If you need to set the export options for your sequence (for example you’ll need to flip the x-axis if you intend to use the sequence in Element 3D), export a single OBJ first (any will do) using – File > Export... > Wavefront OBJ (*.obj) – which allows you to set the options. Then when you export your sequence, those settings are retained for each file.

 

I hope you find it as useful as I have!

40 Comments

Join the discussion and tell us your opinion.

kanareply
21st April 2016 at 4:17 pm

Hello, it’s seems it doesn’t work on r17
at the end, you’ve got “# add buffer 0001 [….] if len(bufferedNumber)<4:”
it should be “if len(bufferedNumber)<4:"
but it doesnt work with that correction.

Rich Hinchcliffereply
21st April 2016 at 4:47 pm
– In reply to: kana

Hi Kana, thanks for pointing that out!

When I pasted the code above from Cinema 4D, it lost all it’s indentation and I think it’s that loss that means the script won’t execute in Cinema. I’ve uploaded the actual Python file here – wordpress-241588-1115649.cloudwaysapps.com/downloads/C4D-to-OBJ.py – Try right-clicking and saving that and then opening it in C4D, or copy pasting from there into the Script Manager instead, see if that works. I’ve just tested the code and it does still work, so I think it must be the lack of tabs/indents that messes it up.

Let me know if the file on the link above works and I’ll replace put it in the main post instead of what’s there :)

Scotreply
2nd February 2017 at 1:38 pm
– In reply to: kana

Hey,
Great script this could be a lifesaver! Have you had any luck with this in R18? I’ve had partial success with one project getting halfway and then crashing but most other projects just bug out and crash C4D. I’m not great with python so not too sure what the issue is……
Thanks in advance!

Rich Hinchcliffereply
2nd February 2017 at 1:43 pm
– In reply to: Scot

Hi Scot.

I’ve not actually tried to use it in R18 myself yet, but if I do I’ll see if I can work out what’s going on. In the mean time, I’ve heard (but not tried myself!) that the new version of Nitrobake (https://nitro4d.com/product/nitrobake2/) has an option to export OBJ sequences – so that might be worth a look?

kanareply
22nd April 2016 at 9:39 am

Hello, yes it works that way !
thanks for sharing this

Rich Hinchcliffereply
22nd April 2016 at 9:43 am
– In reply to: kana

Perfect :) Thanks for letting me know Kana!

Caressereply
27th June 2016 at 9:30 pm

This is amazing! Thank you for sharing!

Caressereply
28th June 2016 at 4:52 pm

Hey Rich, thanks again for this wonderful script. One question – how could the script be modified to change each keyframe into an editable object? I’m using Nitro 4D’s Magic Book plugin. I’ve baked it. But when I go to export the .obj sequence using your handy script, it doesn’t work. When I make each individual frame an editable object and then export, it works. So there’s got to be some command that takes each frame, converts to editable object, then export as .obj – right? Thanks!

Rich Hinchcliffereply
28th June 2016 at 9:53 pm
– In reply to: Caresse

HI Caresse. You say you’ve baked the sequence, but have you tried baking it with another of Nitro 4D’s plugins – Nitrobake? I’ve found that this does exactly the thing you’re asking, and I found it necessary to use this plugin before I exported some things. It not only bakes all the keyframes, but it first makes an editable copy of the object/cloner/whatever that you’re baking the keyframes for. It’s another $45, but I’ve found it to be a very, very useful plugin.

There probably is a way to do it with the script, but I’m not sure where I’d even start with that :) Let me know if you try the Nitrobake plugin and if it’s any use! :)

Caressereply
29th June 2016 at 4:00 pm
– In reply to: Rich Hinchcliffe

Thank you, Rich. I suspected Nitrobake might be the solution. I had purchased Nitrobake last year for an old computer that no longer works. I’m trying to transfer the license over to my work computer, but having some trouble. I emailed Nitro 4D’s support, so we’ll see what happens. Worse comes to worse, I’ll see if my employer can just buy the plugin again. I’ll keep you posted. Thanks again!

Caressereply
30th June 2016 at 10:36 pm
– In reply to: Caresse

Hey Rich, following up: the folks at Nitrobake updated my license so now it’s working! Steadybake is also proving to be just as effective – yesterday it only didn’t work for me because I had applied a cloth to the Magic Book (for thickness) and attempted to bake with the cloth being the highest in the hierarchy. By grouping the two and applying the bake to the null, it worked. The one lingering dilemma is getting the front and back to have different materials, so that when I bring it into AfterEffects via Element3D I can texture the back and front of each page with different videos. I found this plug-in (http://code.vonc.fr/?a=23—–) by César Vonc to help make selecting many faces in one direction simpler. Also, I had to end up using Riptide Pro to do the .obj export, for some reason the material as applied to selection sets didn’t quite work out when exporting using the Lim script. Maybe there’s just some settings I’m too tired to figure out now, haha. Anyway, thank you again for your help!

Nataliareply
28th September 2016 at 8:30 pm

Hey Rich!
I’m from Brazil and have been working on this C4D – Element 3D issue.
I bumped into this post and thought it was really an amazing solution, much better than some plugins I’ve tested…
There was only one little problem: I can’t figure out how to make it work on a Mac. I’ve tried to replace the “\” with “/” (all of them, some of them, and a lot of other combinations), but it simply won’t save the .obj’s in the designed folder. I can go trough all the process, but my folder always end up empty.
Any ideas of what could be wrong? I know the script is made for Windows, but I’ve seen a comment from you on the original post giving some tips to use it on Mac, so I wonder if you could possibly give me some direction…

Anyway, thank you so much for your tips and sorry for any language mistakes! ;)

Rich Hinchcliffereply
9th November 2016 at 1:22 pm
– In reply to: Natalia

Hey Natalia. Sorry it’s taken so long to get back to you – I’ve not been paying much attention to my website recently! Unfortunately I can’t help, as I don’t have much experience with Mac’s.

If I had to take a guess though, I’d probably try get rid of the bit at the bottom that says…


# ask to open containing folder
viewFilesBool = c4d.gui.QuestionDialog("Do you want to open containing folder?")
if viewFilesBool == True:
('explorer "C:\path\of\folder"')
subprocess.Popen('explorer ' + '"' + filePath + '"' )

…as that seems like it could be specific to Windows Explorer? Maybe without those lines the script will run!?

Let me know if you sorted it some other way or if that helps!

Rich

Mitchell Hartreply
31st May 2017 at 9:16 pm
– In reply to: Rich Hinchcliffe

To make this work on Mac OS you’ll need to change two lines
line 27: filePath = filePath + “/”
line 58: c4d.documents.SaveDocument(doc,fileName,c4d.SAVEDOCUMENTFLAGS_0,c4d.FORMAT_OBJEXPORT)
Keep all the spacing the same and you should be good to go :)

Lowellreply
2nd July 2017 at 7:08 pm
– In reply to: Mitchell Hart

Just tried this and it only asks for a save folder and then nothing happens. Also I’m trying it in R18 and it has the same behavior..nothing is executed.

craigreply
26th September 2017 at 9:30 pm

Got the script working on OS Mac with the correction Mitchell suggested. I am wondering if there are any modifications that can be made so that it will kick out Polygon Selection Tags for multiple materials

ziyorokhmanovreply
4th October 2017 at 12:34 pm

thanks man! works on C4D r18

Will Janereply
23rd October 2017 at 3:58 pm

Thank you. Got it working on R16 on mac with the change above.

Chaosreply
26th March 2018 at 11:19 pm

it doesn’t retrieve real fps and time length from project file. crap!

Nidhinreply
5th April 2018 at 12:04 pm

Amazing. Thanks so much, works on r19

Rich Hinchcliffereply
7th May 2018 at 11:45 am
– In reply to: Nidhin

You’re welcome :)

Chakradhar Kreply
18th May 2018 at 5:28 pm

Hi, I have downloaded the script from the link provided. I am using Cinema 4D R17 , but the script is ot loading in the script manager, its blank!
please help me in fixing it!

Rich Hinchcliffereply
13th December 2018 at 2:00 pm
– In reply to: Chakradhar K

I’m not really a programmer so I wouldn’t know where to really start troubleshooting. I’m lucky I found Owen’s script and got it to work at all in the first place :)

Davidreply
8th November 2018 at 4:53 pm

Hello. The script runs fine and it generated MTL files but element did not see them

Orion Frossardreply
9th November 2018 at 9:27 am

Thank you so much ! you rock !

Diego Esquivelreply
12th December 2018 at 4:11 pm

Great to find this. Do you have an updated script for R20? Thanks!

Rich Hinchcliffereply
13th December 2018 at 1:59 pm
– In reply to: Diego Esquivel

Unfortunately not, sorry. I’ve checked the links I have for the original creator of the script, Owen Lim, and he doesn’t seem to have updated it in a while either.

Markreply
8th May 2019 at 2:04 pm
– In reply to: Rich Hinchcliffe

Do you have an update on this? I really need to export .OBJ’s to Element 3D with the right materials and coordinates from R20. I always used RiptidePro but this is not compatible with R20. Plugins like Plexus OBJ Exporter work but wont bring materials in the right way..

Thanks in advance!

Jacob McGrathreply
1st February 2019 at 4:40 am

cant get it on mac os.. it only wants to render 144 frames and my timeline is longer i changed the export settings in the render settings doesnt work, it shows that its exporting but the folder is empty and the objs are no where to be found please help

Rich Hinchcliffereply
4th February 2019 at 4:13 pm
– In reply to: Jacob McGrath

I’m not sure where to start trying to fix it I’m afraid Jacob, especially on a Mac (I use a PC), and I’m not really a programmer and Owen Lim (the original creator of the script who I mention in the post) doesn’t seem to have updated his original behance post. Sorry I can’t be any more help.

Grzegorz Wnukreply
21st July 2019 at 1:01 pm
– In reply to: Jacob McGrath

# Get Animation Length
fromTime = 0
toTime = 150
animLength = toTime – fromTime + 1

Chenge 150 to whatever you have should work !

Verareply
12th March 2019 at 4:45 pm

thank you! it worked like a charm in R19 :)

Rich Hinchcliffereply
14th March 2019 at 5:29 pm
– In reply to: Vera

I’m glad it’s still working for some people!

The Great Cthulhureply
25th October 2019 at 7:56 pm

Hey,
if anyone searches a working Plugin for Cinema 4D R20 I just found the OBJ Sequence Exporter for Cinema 4D by Rowbyte: https://www.rowbyte.com/obj-sequence-exporter
Works like charm for me :D
Cheers

Jasonreply
4th August 2020 at 3:58 pm
– In reply to: The Great Cthulhu

yeppp
thanks a lot, worked for me too… and for those who wonder where is the plugins folder, you just have to create one by yourself

*im on C4D R21

Mikereply
23rd January 2020 at 7:23 pm

Hey Rich, Page not found for the python code. Page has stopped working.

Rich Hinchcliffereply
13th November 2020 at 10:02 am
– In reply to: Mike

The link is fixed now Mike.

andy breply
21st August 2020 at 11:24 pm

Has this link been removed?

Rich Hinchcliffereply
13th November 2020 at 10:01 am
– In reply to: andy b

It had, accidentally! I moved web hosts and that file didn’t get transferred for some reason. Fixed it now. I’m not sure how well it works with the later versions of C4D though – I’ve not used it in a few years.

Christianreply
28th June 2022 at 9:41 pm

Nothing happens when I click Execute

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.