On 27/04/2017 at 08:26, xxxxxxxx wrote:
Hi,
I am new to c4d API, and I have a strange error when trying to use SaveDocument command, using alembic plugin. I am wondering if it's an error in C4D or if I do something wrong...
In a new C4d session/document (R17 or R18), I only create a cube and a cone. (cube is selected, cone is not)
Following that example:
https://github.com/PluginCafe/cinema4d_py_sdk/blob/master/scripts/ExportAlembic.py
I added a 'print', before and after changing the export settings.
import c4d
from c4d import gui
#Welcome to the world of Python
from c4d import documents, plugins
from c4d import documents, plugins, storage
def main() :
# Get Alembic export plugin, 1028082 is its ID
plug = plugins.FindPlugin(1028082, c4d.PLUGINTYPE_SCENESAVER)
if plug is None:
return
# Get a path to save the exported file
filePath ="C:/temp/C4dExport_v001.abc"
op = {}
# Send MSG_RETRIEVEPRIVATEDATA to Alembic export plugin
if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op) :
if "imexporter" not in op:
return
# BaseList2D object stored in "imexporter" key hold the settings
abcExport = op["imexporter"]
if abcExport is None:
return
print 'SELECTION BEFORE: ', abcExport[c4d.ABCEXPORT_SELECTION_ONLY]
# Change Alembic export settings
abcExport[c4d.ABCEXPORT_SELECTION_ONLY] = True
abcExport[c4d.ABCEXPORT_PARTICLES] = True
abcExport[c4d.ABCEXPORT_PARTICLE_GEOMETRY] = True
print 'SELECTION AFTER: ', abcExport[c4d.ABCEXPORT_SELECTION_ONLY]
# Finally export the document
if documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1028082) :
print "Document successfully exported to:"
print filePath
else:
print "Export failed!"
if __name__=='__main__':
main()
The error is:
1- If I didn't open the actual Alembic plugin UI yet (in my c4d session). It seems I can't update the preferences. IE: Before = 0, then I set it to True, After = 0...
The export won't take into consideration the preferences I've tried to set up for abcExport[c4d.ABCEXPORT_SELECTION_ONLY]
2- If I manually open Alembic exporter UI (File --> Export --> Alembic)... I do not need to change anything, I do not need to export (I can cancell).
Then, I can execute my script, and the preferences I'll choose for abcExport[c4d.ABCEXPORT_SELECTION_ONLY] will be taken into consideration...
IE: Before = 0, then I set it to True, After = 1... or Before = 1, then I set it to False, After = 0
Any idea?