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!

15 Comments

Join the discussion and tell us your opinion.

kanareply
April 21, 2016 at 04:04 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
April 21, 2016 at 04:04 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 – richh.co/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
February 02 at 01:02 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
February 02 at 01:02 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
April 22, 2016 at 09:04 AM

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

Rich Hinchcliffereply
April 22, 2016 at 09:04 AM
– In reply to: kana

Perfect 🙂 Thanks for letting me know Kana!

Caressereply
June 27, 2016 at 09:06 PM

This is amazing! Thank you for sharing!

Caressereply
June 28, 2016 at 04:06 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
June 28, 2016 at 09:06 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
June 29, 2016 at 04:06 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
June 30, 2016 at 10:06 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
September 28, 2016 at 08:09 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
November 09, 2016 at 01:11 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
May 31 at 09:05 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
July 02 at 07:07 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.

Leave a reply