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. joel_motion
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 4
    • Best 0
    • Controversial 0
    • Groups 0

    joel_motion

    @joel_motion

    0
    Reputation
    2
    Profile views
    4
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    joel_motion Unfollow Follow

    Latest posts made by joel_motion

    • RE: Script to change Navigation Camera Mode (help)

      @i_mazlov

      Thank you very much for your response!

      I am not sure how long it would have taken me to figure out the "prefsPlugin: c4d.BasePlugin =... " part without your help.

      This is the code I wrote, which works exactly how I wanted it to (and now I have the script mapped to a hotkey).

      import c4d
      
      def main():
          prefsPlugin: c4d.BasePlugin = c4d.plugins.FindPlugin(c4d.PREFS_NAVIGATION, c4d.PLUGINTYPE_PREFS)
      
          navigationValue: int = prefsPlugin[c4d.PREF_NAVIGATION_CAMERA]
          
          if navigationValue == 3:
              prefsPlugin[c4d.PREF_NAVIGATION_CAMERA] = c4d.PREF_NAVIGATION_CAMERA_CAM
              
          else:
               prefsPlugin[c4d.PREF_NAVIGATION_CAMERA] = c4d.PREF_NAVIGATION_CAMERA_CUR
      
      if __name__=='__main__':
          main()
      

      Thanks again!

      posted in Cinema 4D SDK
      joel_motionJ
      joel_motion
    • RE: Script to change Navigation Camera Mode (help)

      @i_mazlov Thanks for the reply!

      This is what I see in the script log when I toggled the navigation preference:
      d1b8c94a-c5d0-44c5-b2fb-928a9602a175-image.png
      I can see that those command "magic numbers" you sent me are close to what I see in my script log (seemingly the "preference" number + the integer corresponding to the option).
      I'm not sure why it didn't show the c4d.CallCommand number in the script log.

      If I wanted to write the script to check what mode is currently in use, would I write something like this?

      if prefs(440000091)[c4d.PREF_NAVIGATION_CAMERA] = 4
             c4d.CallCommand(440000092)
      

      Thanks again for taking time to respond.
      Any information or resources you could share with me would be great!

      posted in Cinema 4D SDK
      joel_motionJ
      joel_motion
    • Script to change Navigation Camera Mode (help)

      I see this in the Documentation under Classic Resource Overview » Navigation
      "Parameter: Camera Mode

      • Parameter ID: c4d.PREF_NAVIGATION_CAMERA
      • Parameter Type: int
      • Cycle Values:
        - Cursor (c4d.PREF_NAVIGATION_CAMERA_CUR)
        - Center (c4d.PREF_NAVIGATION_CAMERA_CTR)
        - Object (c4d.PREF_NAVIGATION_CAMERA_OBJ)
        - Camera (c4d.PREF_NAVIGATION_CAMERA_CAM)
        - Custom (c4d.PREF_NAVIGATION_CAMERA_CUSTOM)"

      It also states "Parameters are accessed with C4DAtom.GetParameter()/C4DAtom.SetParameter()."
      But when I try to use that, I get the error "descriptor 'GetParameter' for 'c4d.C4DAtom' objects doesn't apply to a 'int' object."

      What I'm looking to do is write a script, that I can set to a hotkey, which will toggle between "Cursor" and "Camera" modes. I imagine this should be a simple "if/else" script.
      I run into this problem all the time when building a scene: Say you're setting up and interior/exterior of a house. Inside the house, it's helpful to use the "Camera" mode to navigate, since you're apt to suddenly fly out of the interior when using "Cursor" mode. But whenever you're dealing with the exterior of an object, "Cursor" mode is great!

      Apologies if this is basic. I'm still very much a novice. I have a design background, not computer science. Trying to learn as I go.

      posted in Cinema 4D SDK python 2024 windows
      joel_motionJ
      joel_motion
    • Need help fixing export to GLTF script

      Hi,

      I'm a coding newbie, so I'm often trying to frankenstein code I've found online and then re-write for my purposes.
      I have this script which I pieced together which is supposed to take the top-level of the selected meshes and then individually export each as a GLTF.

      It works, but not without issue. I noticed it would fail if the object had a Redshift material on it (I didn't need materials, so I added the lines to remove the texture tags). Sometimes C4D will crash when the script runs.
      I also noticed that the script will not work (no error or anything) after, separately, doing a regular File->Export->GLTF. Restart C4D and then the script works again.

      Hoping someone here can point out any flaws in my script, something that might solve the above issues, or generally ways to do it better.

      Thanks!

      The code:

      import c4d
      import os
      import string
      
      
      def export_gltf_for_object(obj, save_dir):
          # Create a new temporary document
          temp_doc = c4d.documents.BaseDocument()
      
          # Clone the object and insert it into the temporary document
          cloned_obj = obj.GetClone(c4d.COPYFLAGS_NONE, None)
          temp_doc.InsertObject(cloned_obj)
      
          # Remove material tags from the cloned object
          tags = cloned_obj.GetTags()  # Get a list of all tags on the cloned object
          for tag in tags:
              if isinstance(tag, c4d.TextureTag):  # Check if the tag is a TextureTag (material tag)
                  tag.Remove()  # Remove the tag from the object
      
          # Prepare the file path name
          file_name = obj.GetName() + ".gltf"
          file_path = os.path.join(save_dir, file_name)
      
          # Retrieve and setup the glTF export plugin.
          objExportId = c4d.FORMAT_GLTFEXPORT
          plug = c4d.plugins.FindPlugin(objExportId, c4d.PLUGINTYPE_SCENESAVER)
          if not plug:
              raise RuntimeError("Failed to retrieve the gltf exporter.")
      
          data = {}
          if not plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data):
              raise RuntimeError("Failed to retrieve private data.")
      
          # Retrieve and set export settings
          objExport = data.get("imexporter", None)
          if objExport is None:
              raise RuntimeError("Failed to retrieve BaseContainer private data.")
      
          unit_scale_data = c4d.UnitScaleData()
          unit_scale_data.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_M)  # Adjust as needed
          objExport[c4d.GLTFEXPORTER_UNITSCALE] = unit_scale_data
          objExport[c4d.GLTFEXPORTER_CURRENTFRAME] = True
          objExport[c4d.GLTFEXPORTER_TEXTURES] = False
      
          # Export the temporary document
          if not c4d.documents.SaveDocument(temp_doc, file_path, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, objExportId):
              raise RuntimeError(f"Failed to save the document for object: {obj.GetName()}")
          
          # Close and delete the temporary document from memory
          c4d.documents.KillDocument(temp_doc)
          
          print(f"Document successfully exported to: {file_path}")
      
      def main():
          # Get a directory to save the exported files
          save_dir = c4d.storage.LoadDialog(title="Select directory for OBJ Exports", type=c4d.FILESELECTTYPE_ANYTHING, flags=c4d.FILESELECT_DIRECTORY)
          if not save_dir:
              return
      
          active_doc = c4d.documents.GetActiveDocument()
          selected_objects = active_doc.GetActiveObjects(0)  # 0 means no hierarchy, only top-level selected objects
      
          for obj in selected_objects:
              export_gltf_for_object(obj, save_dir)
      
      if __name__ == '__main__':
          main()
      
      posted in General Talk
      joel_motionJ
      joel_motion