Hi,
please for you next post, follow our guildelines, using the forum function to mark your thread as a question or solve once it's done help us a lot. Also, tags can help us to faster reproduce the issue.
we got an example on github about exporting obj. I've adapte the code to export gltf
And please don't ask the question on different forum, otherwise you will waste people time.
In your case, you are changing a userdata value. Using c4d.EventAdd()
in a loop will (may not) update cinema4D on each loop. c4d.EventAdd() just push an event on a stack.
Instead, you may want to use ExecutePasses. This will update the scene without updating the editor. On some specific case, you must call it twice in a row to be sure the scene is updated.
import c4d
def main():
# Retrieves a path to save the exported file
filePath = c4d.storage.LoadDialog(title="Save File for OBJ Export", flags=c4d.FILESELECT_SAVE, force_suffix="gltf")
if not filePath:
return
print (filePath)
# Retrieves glft export plugin.
objExportId = c4d.FORMAT_GLTFEXPORT
plug = c4d.plugins.FindPlugin(objExportId, c4d.PLUGINTYPE_SCENESAVER)
if plug is None:
raise RuntimeError("Failed to retrieve the gltf exporter.")
data = dict()
# Sends MSG_RETRIEVEPRIVATEDATA to gltf export plugin
if not plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data):
raise RuntimeError("Failed to retrieve private data.")
# BaseList2D object stored in "imexporter" key hold the settings
objExport = data.get("imexporter", None)
if objExport is None:
raise RuntimeError("Failed to retrieve BaseContainer private data.")
# Defines gltf export settings
objExport[c4d.GLTFEXPORTER_UNITSCALE] = 2.0
objExport[c4d.GLTFEXPORTER_CURRENTFRAME] = True
# Finally export the document
if not c4d.documents.SaveDocument(doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, objExportId):
raise RuntimeError("Failed to save the document.")
print("Document successfully exported to:", filePath)
if __name__ == '__main__':
main()
Cheers,
Manuel