Repository navigation
Expand file tree
/
Copy pathexport_obj.py
More file actions
57 lines (45 loc) · 2.11 KB
/
Copy pathexport_obj.py
File metadata and controls
57 lines (45 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Exports Obj with custom settings.
Topics:
* c4d.plugins.FindPlugin()
* MSG_RETRIEVEPRIVATEDATA
* c4d.documents.SaveDocument()
"""
__author__ = "Joey Gaspe"
__copyright__ = "Copyright (C) 2026 MAXON Computer GmbH"
__license__ = "Apache-2.0 License"
__version__ = "R13"
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="obj")
if not filePath:
return
# Retrieves Obj export plugin, defined in R17 as FORMAT_OBJ2EXPORT and below R17 as FORMAT_OBJEXPORT
objExportId = c4d.FORMAT_OBJEXPORT if c4d.GetC4DVersion() < 17000 else c4d.FORMAT_OBJ2EXPORT
plug = c4d.plugins.FindPlugin(objExportId, c4d.PLUGINTYPE_SCENESAVER)
if plug is None:
raise RuntimeError("Failed to retrieve the OBJ exporter.")
data = dict()
# Sends MSG_RETRIEVEPRIVATEDATA to OBJ 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 OBJ export settings
if c4d.GetC4DVersion() > 22600:
objExport[c4d.OBJEXPORTOPTIONS_EXPORT_UVS] = c4d.OBJEXPORTOPTIONS_UV_ORIGINAL
else:
objExport[c4d.OBJEXPORTOPTIONS_TEXTURECOORDINATES] = True
if c4d.GetC4DVersion() >= 24105:
objExport[c4d.OBJEXPORTOPTIONS_MATERIAL] = c4d.OBJEXPORTOPTIONS_MATERIAL_ORIGINAL_PATHS
else:
objExport[c4d.OBJEXPORTOPTIONS_MATERIAL] = c4d.OBJEXPORTOPTIONS_MATERIAL_MATERIAL
objExport[c4d.OBJEXPORTOPTIONS_ANIMATION_TYPE] = c4d.OBJEXPORTOPTIONS_NO_ANIMATION
# 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()