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

    OBJ Import setting not changing

    Cinema 4D SDK
    python 2024 windows
    2
    5
    839
    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.
    • .
      .del
      last edited by

      Hi -

      I'm looking at the git hub example for obj import and ran that code as it is and it leaves me wondering if changing the import settings is working. Based on the git hub script the phong tag should come in at 22.5 degrees.

      Another strange thing. I set my preferences to a phong of 60 degrees and closed the preference panel. Then I ran the script which should have imported the obj at 22.5 but instead it actually came in at 180 degrees.

      Is it possible that the documentation or perhaps the python implementation is incorrect?

      thanks,
      .del

      Straight from the git -

      """
      Copyright: MAXON Computer GmbH
      Author: Joey Gaspe
      
      Description:
          - Imports Obj with custom settings.
      
      Class/method highlighted:
          - c4d.plugins.FindPlugin()
          - MSG_RETRIEVEPRIVATEDATA
          - c4d.documents.MergeDocument()
      
      """
      import c4d
      
      
      def main():
          # Retrieves a path to load the imported file
          selectedFile = c4d.storage.LoadDialog(title="Load File for OBJ Import", type=c4d.FILESELECTTYPE_ANYTHING, force_suffix="obj")
          if not selectedFile:
              return
      
          # Retrieves Obj import plugin, defined in R17 as FORMAT_OBJ2IMPORT and below R17 as FORMAT_OBJIMPORT
          objExportId = c4d.FORMAT_OBJIMPORT if c4d.GetC4DVersion() < 17000 else c4d.FORMAT_OBJ2IMPORT
          plug = c4d.plugins.FindPlugin(objExportId, c4d.PLUGINTYPE_SCENELOADER)
          if plug is None:
              raise RuntimeError("Failed to retrieve the obj importer.")
      
          data = dict()
          # Sends MSG_RETRIEVEPRIVATEDATA to OBJ import 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
          objImport = data.get("imexporter", None)
          if objImport is None:
              raise RuntimeError("Failed to retrieve BaseContainer private data.")
      
          # Defines the settings
          objImport[c4d.OBJIMPORTOPTIONS_PHONG_ANGLE_DEFAULT] = 22.5
          if c4d.GetC4DVersion() > 22600:
              objImport[c4d.OBJIMPORTOPTIONS_IMPORT_UVS] = c4d.OBJIMPORTOPTIONS_UV_ORIGINAL
          else:
              objImport[c4d.OBJEXPORTOPTIONS_TEXTURECOORDINATES] = True
      
          objImport[c4d.OBJIMPORTOPTIONS_SPLITBY] = c4d.OBJIMPORTOPTIONS_SPLITBY_OBJECT
          objImport[c4d.OBJIMPORTOPTIONS_MATERIAL] = c4d.OBJIMPORTOPTIONS_MATERIAL_MTLFILE
          objImport[c4d.OBJIMPORTOPTIONS_POINTTRANSFORM_FLIPZ] = True
      
          # Finally imports without dialogs
          if not c4d.documents.MergeDocument(doc, selectedFile, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None):
              raise RuntimeError("Failed to load the document.")
      
          # Pushes an update event to Cinema 4D
          c4d.EventAdd()
      
      
      if __name__ == '__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • .
        .del
        last edited by .del

        I figured it out.

        objImport[c4d.OBJIMPORTOPTIONS_PHONG_ANGLE_DEFAULT] = 22.5
        

        This needs to be in radians versus degrees.

        ferdinandF 1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @.del
          last edited by

          Hello @del,

          thank you for reaching out to us and for posting the solution to your problem. As a gentle reminder, all angular values in Cinema 4D are stored in radians. In addition to the function math.radians (and .degrees) there is c4d.utils.RadToDeg (and .DegToRad) to convert between radians and degrees.

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 0
          • .
            .del
            last edited by

            Hi @ferdinand -

            What do you think about changing the git file to math.radians(22.5)?

            Thanks,
            .del

            ferdinandF 1 Reply Last reply Reply Quote 0
            • ferdinandF
              ferdinand @.del
              last edited by

              Hey @del,

              Thank you for pointing out that this part of our examples, I overlooked this aspect this morning. I have fixed the issue in our local repository for import_obj_r13.py. The updated line is:

              objImport[c4d.OBJIMPORTOPTIONS_PHONG_ANGLE_DEFAULT] = c4d.utils.DegToRad(22.5)
              

              and it will go live with the next docs update. I cannot update the legacy version of the SDK in import_OBJ.py as I lack the permissions to write there even in our local repository.

              Cheers,
              Ferdinand

              MAXON SDK Specialist
              developers.maxon.net

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