Hello @Aleksey ,
Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:
About your First Question
The problem with ChatGPT, as amazing as its principal abilities are, is that it seems to struggle with how im- and exporters work in our API. And in true ChatGPT fashion it then starts making up things which simply do not exist, as for example c4d.FBXEXPORT_SELECTION_ONLY = True
or the fifth SaveDocument
argument.
The problem which arises here for us is that this whole workflow, not writing code manually and serving here that automatically generated for others to fix, is in essence a violation our guidelines as lined out in Forum Guidelines: Scope of Support:
- If necessary, we will provide code examples, but we will not provide full solutions or design applications.
- "It doesn't work" is not a support request and ultimately, we will not debug code, but instead provide answers to specific problems.
Or in short, the rule of every coding-community in the world also does apply here: "we will not do your homework for you". There are of course nuances here, and ChatGPT differs at least a little from straight up asking for a solution. But in the end, we cannot fix the code for everyone who is able to use ChatGPT but does not know our APIs or how to use Python/C++ in general. We would be simply overwhelmed by this, our support has always the goal to help users being able to help themselves in the future by understanding something fundamentally.
We had a brief talk about this subject this morning and haven't come to a full conclusion on how we will deal with this in the future. To be clear here, the fault does not lie with you, @Aleksey, as nothing explicitly forbids this being done at the moment. But we might restrict support requests which are based on code that clearly has been automatically generated. We can of course see the advantages in allowing this for the community, having an easy entry point for them. But at the same time, the sheer amount of support requests this could entail is a problem.
The Python example export_obj_r13.py demonstrates how to modify the settings of an im- or exporter plugin at the case of the OBJ exporter. I also provided an example specific to this case below.
Cheers,
Ferdinand
Code:
"""Provides an example for setting the parameters of an im- or exporter plugin.
See also:
https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/scripts/
03_application_development/files_media/export_obj_r13.py
"""
import c4d
import os
doc: c4d.documents.BaseDocument # The active document.
def main():
"""
"""
# Check that there is document path to infer from the active document.
if doc.GetDocumentPath() == "":
c4d.gui.MessageDialog("Cannot infer save location from unsaved document.")
return
# Get the selected objects
selectedObjects: list[c4d.BaseObject] = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
if not selectedObjects:
c4d.gui.MessageDialog("No objects selected. Please select at least one object and try again.")
return
# Get the FBX exporter plugin.
plugin: c4d.plugins.BasePlugin = c4d.plugins.FindPlugin(
c4d.FORMAT_FBX_EXPORT, c4d.PLUGINTYPE_SCENESAVER)
if not plugin:
raise RuntimeError("Could not find FBX exporter plugin.")
# Get the internal data so that we write the setting we want to write, handling the settings
# of im- and exporter plugins is a bit fiddly as the plugin node itself does not hold these
# parameters.
privateData: dict = {}
if not plugin.Message(c4d.MSG_RETRIEVEPRIVATEDATA, privateData):
raise RuntimeError("Failed to retrieve private FBX exporter plugin data.")
settings: c4d.BaseList2D = privateData.get("imexporter", None)
if settings is None:
raise RuntimeError("Failed to retrieve settings node for FBX exporter plugin.")
# The is just normal parameter access.
settings[c4d.FBXEXPORT_SELECTION_ONLY] = True
# Now we can invoke the exporter with the settings we have defined.
documentName: str = f"{doc.GetDocumentName()}_{selectedObjects[0].GetName()}"
filePath: str = os.path.join(doc.GetDocumentPath(), documentName)
res: bool = c4d.documents.SaveDocument(
doc, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_FBX_EXPORT)
if res:
c4d.gui.MessageDialog(f"FBX export successful: {filePath}")
else:
c4d.gui.MessageDialog("FBX export failed. Please check the file path and try again.")
if __name__=='__main__':
main()