Cannot export to FBX from command line
-
On 03/01/2017 at 03:33, xxxxxxxx wrote:
Hi Thomas,
To export an FBX from command line, SaveDocument() has to be called from another thread.
Here's the solution:import c4d from c4d import documents, threading import sys FBX_EXPORTER_ID = 1026370 class ExportThread(threading.C4DThread) : def __init__(self, doc) : self.doc = doc self.status = False def Main(self) : # Export document to FBX self.status = documents.SaveDocument(self.doc, DEST_FILE, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, FBX_EXPORTER_ID) def GetStatus(self) : return self.status def ExportFBX() : # Load document load = documents.LoadFile(SOURCE_FILE) if not load: return False # Get loaded document doc = documents.GetActiveDocument() if doc is None: return False # Clone document clone = doc.GetClone(c4d.COPYFLAGS_DOCUMENT) if clone is None: return False thread = ExportThread(clone) thread.Start() # Start thread thread.End() # Then end it but wait until it finishes # Retrieve export status and return it status = thread.GetStatus() return status def PluginMessage(id, data) : if id==c4d.C4DPL_COMMANDLINEARGS: if 'ExportFBX' in sys.argv: print "FBX Export Started" ret = ExportFBX() if ret: print "FBX Export Succeeded" else: print "FBX Export Failed!" return True return False
To test this code save it to a pyp file in your plugins directory. Then run Cinema 4D's in Command Line passing "ExportFBX" argument.
The thread solution also works well and is fast when Cinema 4D interface is running.
-
On 03/01/2017 at 07:29, xxxxxxxx wrote:
Hi Yannick, thanks for your reply. Unfortunately this did not work,
I ran your plugin with
/Applications/MAXON/CINEMA\ 4D\ R18/CINEMA\ 4D.app/Contents/MacOS/CINEMA\ 4D -nogui ExportFBX
Then did get
FBX Export Succeeded
But no file was written. Again, using
FBX_EXPORTER_ID = c4d.FORMAT_C4DEXPORT
does write a file.
I'm wondering if the FBX exporter's id 1026370 is still valid.. but couldn't find it in the C++ SDK as gr4ph0s suggested.. although it works when the interface is running.. I'm using R18 btw. -
On 03/01/2017 at 08:54, xxxxxxxx wrote:
The FBX exporter ID is fine. I tested the code I posted on Windows but not on Mac.
Have you tried to execute Commandline.app instead of Cinema 4D.app? This app should be used instead of the normal one for Command Line operations.
-
On 04/01/2017 at 07:41, xxxxxxxx wrote:
Hi Yannick,
Well, still no luck here, even on Windows with R18. However, the file exports fine with R15. Which version did you use ? I'm going to try on R17 now. -
On 04/01/2017 at 07:48, xxxxxxxx wrote:
Also working with R17, can you confirm you get the same result with R18 on your side ?
-
On 04/01/2017 at 09:46, xxxxxxxx wrote:
Hi,
I confirm there's an issue exporting FBX files in command line with R18 indeed. It will be fixed with the next update.
-
On 04/01/2017 at 10:06, xxxxxxxx wrote:
Alright, Is there a bug tracker or do you have a rough idea when this will be available ?
Thanks a lot for your help! -
On 05/01/2017 at 04:33, xxxxxxxx wrote:
There's only an internal bug tracker. Hopefully an update will be released soon.
-
On 06/01/2017 at 10:37, xxxxxxxx wrote:
Hi I ran into another problem and I couldn't find a solution, it seems that C4D will try to load any file which path is passed as an argument.
For example :
"/Applications/MAXON/CINEMA 4D R17/Commandline.app/Contents/MacOS/Commandline" -ExportFBX -src "[absolute path]/testScene.c4d" -dst "[absolute path]/testScene.fbx"
crashes C4D, apparently because it's trying to load the fbx."/Applications/MAXON/CINEMA 4D R17/Commandline.app/Contents/MacOS/Commandline" "[absolute path]/testScene.fbx"
crashes it too.I tried to "consume" arguments in sys.arg in pluginMessage(id=C4DPL_COMMANDLINEARGS) but the crash occurs before that.
So far, the only way I found arround that is to omit the file extension in the paths provided as arguments
For example :
"/Applications/MAXON/CINEMA 4D R17/Commandline.app/Contents/MacOS/Commandline" -ExportFBX -src "[absolute path]/testScene" -dst "[absolute path]/testScene"Then i can append the file extensions in the script but I have to assume the file extension is lower case, Is there a better way ?
Thanks. -
On 09/01/2017 at 08:42, xxxxxxxx wrote:
Hi Thomas,
The sys.argv command line arguments passed to C4DPL_COMMANDLINEARGS plugin message can't be consumed currently.
I'll see if a better workaround can be used to avoid Cinema 4D from loading filenames passed as command line arguments.
-
On 08/03/2017 at 05:51, xxxxxxxx wrote:
Hi Thomas,
Sorry for my late reply.
A workaround to avoid Cinema from recognizing file paths is to merge the command switches -src and -dst with the file names in the same strings, for instance:
-ExportFBX "-src [absolute path]/testScene.c4d" "-dst [absolute path]/testScene.fbx"The string can then be split like this:
srcSwitch, srcFile = arg.split(' ', 1) if srcSwitch != '-src': return False # This line is needed to fix spaces on OSX srcFile = srcFile.replace('\\ ', ' ')
-
On 01/08/2017 at 04:22, xxxxxxxx wrote:
~~I am running into this problem as well in R18 (SP3); both Commandline and -nogui options will return true for the save command but no FBX file is written.
Any new information on a resolution would be wonderful, if available.
Thanks!
~~
EDIT:
I retract this; after updating I had not retried a thread solution. I can confirm The ExportFBX example provided in this thread works properly for both Commandline and -nogui in Cinema 4D R18.057, resulting in a file being written.