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
    1. Maxon Developers Forum
    2. Aleksey
    3. Posts
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 4
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by Aleksey

    • RE: Export fbx of only selected objects

      @ferdinand THanks! I got it to work!

      I totally understand the issues with providing support for chatGPT, but don't be so hard on it, adding "c4d.FBXEXPORT_SELECTION_ONLY = True" was the work of my hands 🙂 So that wasn't it's mistake.

      I grabbed that command from here: https://developers.maxon.net/docs/py/2023_2/classic_resource/file_base/ffbxexport.html?highlight=fbx export

      Currently i find chat GPT is super handy for commenting existing scripts and figuring out how they work.

      So i am actually learning, not just pasting chat gpt code 🙂

      posted in Cinema 4D SDK
      A
      Aleksey
    • RE: Export fbx of only selected objects

      @mogh

      Thanks man, yeah im starting to catch on that it's using old code in places..

      I removed the 4th parameter, but now it's giving me the error message dialogue 😞 ( something about the filepath failure.

      i tried getting the filepath building from the first script, because that one actually worked, just refuses to export only selected object. but the 2nd script did not like that either..

      i feel so close! yet so far away 🙂

      posted in Cinema 4D SDK
      A
      Aleksey
    • RE: Export fbx of only selected objects

      all cards on the table, i'm using chat gpt to write this script. :)) It was very helpful at modifying existing scripts, but seems to be failing here.

      after some reading i found some info about loading a plugin 1026370. so i got it to write a new script:

      import os
      import c4d
      from c4d import documents, gui
      
      def main():
          # Get the active document and the current path
          doc = documents.GetActiveDocument()
          doc_path = doc.GetDocumentPath()
          doc_name = doc.GetDocumentName()
      
          # Get the selected objects
          selected_objects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
      
          # Check if there are any selected objects
          if not selected_objects:
              gui.MessageDialog('No objects selected. Please select at least one object and try again.')
              return
      
          # Set the FBX export path and name
          first_obj_name = selected_objects[0].GetName()
          fbx_name = '{}_{}.fbx'.format(doc_name, first_obj_name)
          fbx_path = os.path.join(doc_path, fbx_name)
      
          # Initialize FBX export settings
          fbx_export_settings = c4d.BaseContainer()
          fbx_export_settings.SetBool(c4d.FBXEXPORT_ASCII, True)
          fbx_export_settings.SetBool(c4d.FBXEXPORT_EMBED_TEXTURES, False)
          fbx_export_settings.SetBool(c4d.FBXEXPORT_SELECTION_ONLY, True)
      
          # Get the FBX exporter plugin ID
          fbx_exporter_id = c4d.FBX_EXPORTVERSION_7_5_0
          if fbx_exporter_id == 0:
              fbx_exporter_id = 1026370  # Use the plugin ID directly for Cinema 4D 2023.1
      
          # Export the selected objects to an FBX file
          result = documents.SaveDocument(doc, fbx_path, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 
                                          fbx_exporter_id, fbx_export_settings)
      
          if result:
              gui.MessageDialog('FBX export successful: {}'.format(fbx_path))
          else:
              gui.MessageDialog('FBX export failed. Please check the file path and try again.')
      
      if __name__=='__main__':
          main()
      

      but now i get an error: TypeError: function takes at most 4 arguments (5 given)

      posted in Cinema 4D SDK
      A
      Aleksey
    • Export fbx of only selected objects

      I'm trying to write a simple script to export an fbx of the selected objects.

      import c4d
      import os
      
      def main():
          # Get the currently open document
          doc = c4d.documents.GetActiveDocument()
          if doc is None:
              return
      
          # Get the selected objects
          selected_objects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
      
          if not selected_objects:
              return
      
          # Get the file path of the currently open document
          filepath = doc.GetDocumentPath()
          if not filepath:
              return
      
          # Get the name of the currently open document
          docname = os.path.splitext(doc.GetDocumentName())[0]
      
          # Get the name of the first selected object
          first_object_name = selected_objects[0].GetName()
          
      
          # Create the FBX file path and name
          fbx_filepath = os.path.join(filepath, docname + "_" + first_object_name + ".fbx")
          
          #make fbx exporter only export selected object
          c4d.FBXEXPORT_SELECTION_ONLY = True
      
          # Export the selected objects as an FBX file
          c4d.documents.SaveDocument(doc, fbx_filepath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1026370)
      
      if __name__ == '__main__':
          main()
      

      But it keeps exporting the whole scene.
      Sorry im a total noob at this.

      posted in Cinema 4D SDK python
      A
      Aleksey