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

    STEP/STP FILE IMPORT PYTHON DOCUMENTATION

    Cinema 4D SDK
    r20 python
    3
    5
    3.5k
    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.
    • T
      Telerak
      last edited by Telerak

      I've been looking all over for Python documentation for STEP file imports for a few days, and haven't come across any solid info yet. Has anyone else found where this information might be found? Thanks!

      Edit: I'm trying to import STEP files with specific settings as to not create a prompt window that usually happens when importing STEP files.

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by

        Hello Telerak,

        here's an example for the OBJ Import: https://github.com/PluginCafe/cinema4d_py_sdk/blob/master/scripts/FileImportExport/import_OBJ.py
        You may want to adapt the code for STEP import.

        Cheers,
        Robert

        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by

          Hi @Telerak, first of all, welcome in the plugincafe community.
          Just a little request for your next topics, please mark your topic as a question see , I've done it this time, no worry at all.

          You can find an example of the step file import bellow.

          """
          Copyright: MAXON Computer GmbH
          Author: Maxime Adam
          
          Description:
              - Import STP/STEP with custom settings.
          
          Class/method highlighted:
              - c4d.plugins.FindPlugin()
              - MSG_RETRIEVEPRIVATEDATA
              - c4d.documents.MergeDocument()
              
          Documentation:
              - https://developers.maxon.net/docs/py/2023_2/consts/FORMAT_export.html
              - https://developers.maxon.net/docs/cpp/2023_2/_fcadimport_8h.html
          
          Compatible:
              - Win / Mac
              - R20
          """
          import c4d
          
          
          def main():
              # Retrieves a path to load the imported file
              selectedFile = c4d.storage.LoadDialog(title="Load File for STEP Import", type=c4d.FILESELECTTYPE_ANYTHING, force_suffix="step")
              if not selectedFile:
                  return
          
              # Retrieves STEP import plugin
              plug = c4d.plugins.FindPlugin(c4d.FORMAT_STEPIMPORT, c4d.PLUGINTYPE_SCENELOADER)
              if plug is None:
                  raise RuntimeError("Failed to retrieves the STEP importer.")
          
              data = dict()
              # Sends MSG_RETRIEVEPRIVATEDATA to OBJ import plugin
              if not plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data):
                  raise RuntimeError("Failed to retrieves private data.")
          
              # BaseList2D object stored in "imexporter" key hold the settings
              stepImport = data.get("imexporter", None)
              if stepImport is None:
                  raise RuntimeError("Failed to retrieves BaseContainer private data.")
          
              # Defines the settings
              stepImport[c4d.CADIMPORT_SPLINES] = False
          
              stepImport[c4d.CADIMPORT_ORIGINAL_UNITS] = False
              # Sets the data by Scaling 10x and set to mm units
              scale = c4d.UnitScaleData()
              scale.SetUnitScale(10, c4d.DOCUMENT_UNIT_vMM)
              stepImport[c4d.CADIMPORT_SCALE] = scale
          
              # 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.")
          
              c4d.EventAdd()
          
          
          if __name__ == '__main__':
              main()
          
          

          Finally, you can find symbols for importer/exporter in FORMAT EXPORT page. Unfortunately, for options you have to search the C++ documentation, here the ones for STEP file Fstepimport.h as you can see it is not that much here, but if you take a look at the res files (Cinema 4D R20\resource\modules\cadexchange\description\Fstepimport.res) it also include Fcadimport resource so, that means you can also define the value from Fcadimport.h

          I know the documentation get room to be improved on this topic. I will see what's possible to do.
          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 2
          • M
            mp5gosu
            last edited by m_adam

            Just want to add: You can also drag the import settings parameters from the preferences dialog to the python console, so the symbol names show up there.

            Edit @m_adam: For more information see Python Console - Drag and Drop.

            1 Reply Last reply Reply Quote 1
            • T
              Telerak
              last edited by

              @mp5gosu @m_adam I'll test out these options and see how it works out. Thanks for the information guys, I appreciate it!

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