Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    FBX does not export

    Cinema 4D SDK
    windows 2024 python
    2
    2
    340
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pyxelriggerP
      pyxelrigger
      last edited by

      Im developing a simple script to export an .FBX just the "Joints" object of each .c4d file in a folder, it works without any errors on console but it doesn't create any .FBX file in the folder I define

      import c4d
      import os
      
      def main() -> None:
          plugin = c4d.plugins.FindPlugin(c4d.FORMAT_FBX_EXPORT, c4d.PLUGINTYPE_SCENESAVER)
          #print (plugin)
      
          data = {}
          plugin.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data)
      
      
          settings = data.get("imexporter", None)
          #print (settings)
          
              
          settings[c4d.FBXEXPORT_FBX_VERSION] = False
          settings[c4d.FBXEXPORT_ASCII] = False
          settings[c4d.FBXEXPORT_CAMERAS] = False
          settings[c4d.FBXEXPORT_LIGHTS] = False
          settings[c4d.FBXEXPORT_SPLINES] = False
          settings[c4d.FBXEXPORT_INSTANCES] = False
          settings[c4d.FBXEXPORT_SELECTION_ONLY] = True
          settings[c4d.FBXEXPORT_GLOBAL_MATRIX] = False
          settings[c4d.FBXEXPORT_SDS] = c4d.FBXEXPORT_SDS_GENERATOR
          settings[c4d.FBXEXPORT_TRIANGULATE] = False
          settings[c4d.FBXEXPORT_SAVE_NORMALS] = True
          settings[c4d.FBXEXPORT_SAVE_VERTEX_COLORS] = False
          settings[c4d.FBXEXPORT_SAVE_VERTEX_MAPS_AS_COLORS] = False
          settings[c4d.FBXEXPORT_UP_AXIS] = c4d.FBXEXPORT_UP_AXIS_Y
          settings[c4d.FBXEXPORT_TRACKS] = True
          settings[c4d.FBXEXPORT_BAKE_ALL_FRAMES] = False
          settings[c4d.FBXEXPORT_PLA_TO_VERTEXCACHE] = False
          settings[c4d.FBXEXPORT_BOUND_JOINTS_ONLY] = False
          settings[c4d.FBXEXPORT_TAKE_MODE] = c4d.FBXEXPORT_TAKE_TAKES
          settings[c4d.FBXEXPORT_MATERIALS] = True
          settings[c4d.FBXEXPORT_EMBED_TEXTURES] = False
          settings[c4d.FBXEXPORT_SUBSTANCES] = True
          settings[c4d.FBXEXPORT_BAKE_MATERIALS] = True
          settings[c4d.FBXEXPORT_BAKEDTEXTURE_WIDTH] = 1024
          settings[c4d.FBXEXPORT_BAKEDTEXTURE_HEIGHT] = 1024
          settings[c4d.FBXEXPORT_BAKEDTEXTURE_RESIZE] = c4d.FBXEXPORT_BAKEDTEXTURE_RESIZE_OFF
          settings[c4d.FBXEXPORT_BAKEDTEXTURE_FORMAT] = int(8)
          settings[c4d.FBXEXPORT_BAKEDTEXTURE_DEPTH] = c4d.FBXEXPORT_BAKEDTEXTURE_DEPTH_8
          settings[c4d.FBXEXPORT_LOD_SUFFIX] = False
      
      
          c4dfilesfolder = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, '.C4D Animations Folder', c4d.FILESELECT_DIRECTORY, '','', '')
          c4dfileslist = os.listdir(c4dfilesfolder)
      
      
          exportpath = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, 'Save .FBX Files', c4d.FILESELECT_DIRECTORY, '','', '')
          
          c4dpath = ''
          for file in c4dfileslist :
              c4dpath = '{}\{}'.format(c4dfilesfolder, file)
              doc = c4d.documents.LoadDocument(c4dpath, c4d.SCENEFILTER_OBJECTS)
              if not doc:
                  print ('NONE DOC')
              else:
                  
                  doc.SetSelection(doc.SearchObject('Joints'), c4d.SELECTION_NEW)
                  c4d.documents.SaveDocument(doc, exportpath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_FBX_EXPORT)
                  c4d.documents.KillDocument(doc)
              
      if __name__ == '__main__':
          main()
      
      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @pyxelrigger
        last edited by

        Hey @pyxelrigger,

        Thank you for reaching out to us. It is always difficult for me in these cases to find the right words. Generally speaking, what you ask us to do here, is out of scope of support: Either debug your code or finish the script for you.

        What I see here is primarily a user who is overwhelmed by his or her own code. Especially when you are less experienced: Just break up things into manageable pieces where you know what they do and you can confirm that they do what you mean them to do. And when I run into troubles, the first thing I would also remove is all UI fluff. You could for example define your paths just at the top of the script. Finally, NEVER do this c4dpath = '{}\{}'.format(c4dfilesfolder, file), this is just bound to go wrong. Use os.path.join instead.

        You will have to debug your script yourself.

        Cheers,
        Ferdinand

        Result:

        Exported /Users/f_hoppe/Desktop/test/Untitled 2.fbx
        Exported /Users/f_hoppe/Desktop/test/Untitled 1.fbx
        

        Code (mostly AI generated):

        import c4d
        import os
        
        def SetFbxExportSettings() -> None:
            """Set the FBX export settings.
            """
            plugin: c4d.plugins.BasePlugin = c4d.plugins.FindPlugin(c4d.FORMAT_FBX_EXPORT, c4d.PLUGINTYPE_SCENESAVER)
        
            data: dict = {}
            plugin.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data)
            settings = data.get("imexporter", None)
            if settings is None:
                raise ValueError("Could not retrieve the FBX export settings.")
        
            settings[c4d.FBXEXPORT_FBX_VERSION] = False
            settings[c4d.FBXEXPORT_ASCII] = False
            settings[c4d.FBXEXPORT_CAMERAS] = False
            settings[c4d.FBXEXPORT_LIGHTS] = False
            settings[c4d.FBXEXPORT_SPLINES] = False
            settings[c4d.FBXEXPORT_INSTANCES] = False
            settings[c4d.FBXEXPORT_SELECTION_ONLY] = True
            settings[c4d.FBXEXPORT_GLOBAL_MATRIX] = False
            settings[c4d.FBXEXPORT_SDS] = c4d.FBXEXPORT_SDS_GENERATOR
            settings[c4d.FBXEXPORT_TRIANGULATE] = False
            settings[c4d.FBXEXPORT_SAVE_NORMALS] = True
            settings[c4d.FBXEXPORT_SAVE_VERTEX_COLORS] = False
            settings[c4d.FBXEXPORT_SAVE_VERTEX_MAPS_AS_COLORS] = False
            settings[c4d.FBXEXPORT_UP_AXIS] = c4d.FBXEXPORT_UP_AXIS_Y
            settings[c4d.FBXEXPORT_TRACKS] = True
            settings[c4d.FBXEXPORT_BAKE_ALL_FRAMES] = False
            settings[c4d.FBXEXPORT_PLA_TO_VERTEXCACHE] = False
            settings[c4d.FBXEXPORT_BOUND_JOINTS_ONLY] = False
            settings[c4d.FBXEXPORT_TAKE_MODE] = c4d.FBXEXPORT_TAKE_TAKES
            settings[c4d.FBXEXPORT_MATERIALS] = True
            settings[c4d.FBXEXPORT_EMBED_TEXTURES] = False
            settings[c4d.FBXEXPORT_SUBSTANCES] = True
            settings[c4d.FBXEXPORT_BAKE_MATERIALS] = True
            settings[c4d.FBXEXPORT_BAKEDTEXTURE_WIDTH] = 1024
            settings[c4d.FBXEXPORT_BAKEDTEXTURE_HEIGHT] = 1024
        
        def GetInputDocumentPaths() -> list[str]:
            """Opens a directory dialog to select a folder and returns a list of Cinema 4D documents that 
            are in the selected folder or its subfolders.
            """
            path: str = c4d.storage.LoadDialog(
                c4d.FILESELECTTYPE_ANYTHING, "Animations", c4d.FILESELECT_DIRECTORY)
            if not os.path.isdir(path):
                raise ValueError("The given path is not a directory.")
            
            files: list[str] = []
            for root, _, filenames in os.walk(path):
                for filename in filenames:
                    if filename.endswith('.c4d'):
                        files.append(os.path.join(root, filename))
            return files
        
        def main() -> None:
            """Main function.
            """
            # Set the settings and get the inputs.
            SetFbxExportSettings()
            filePaths: list[str] = GetInputDocumentPaths()
        
            # Export the documents in the list to FBX.
            for path in filePaths:
                # Load the document.
                doc: c4d.documents.BaseDocument = c4d.documents.LoadDocument(path, c4d.SCENEFILTER_OBJECTS)
                if not doc:
                    raise ValueError(f"Could not load the document at {path}.")
                
                # Get the first object in the document and set it as the selection so that it is exported.
                obj: c4d.BaseObject = doc.GetFirstObject()
                if not obj:
                    raise ValueError(f"The document at {path} does not contain any objects.")
                
                doc.SetSelection(obj, c4d.SELECTION_NEW)
        
                # Export the document to FBX and close it.
                fbxPath: str = path.replace('.c4d', '.fbx')
                c4d.documents.SaveDocument(doc, fbxPath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_FBX_EXPORT)
                c4d.documents.KillDocument(doc)
        
                print(f"Exported {fbxPath}")
                
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • First post
          Last post