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

    How to get explicit import node space?

    Cinema 4D SDK
    windows python 2025
    2
    3
    91
    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.
    • DunhouD
      Dunhou
      last edited by

      Hey community,

      I want to get the explicit render engine name of the default import plugin but not the index, can I do this?

      e.g. I want to set the importor to Standard or Redshift, but if I remove some renderer like CentiLeo, the index of Standard will changed.

      Cheers~
      DunHou

      35e08814-bb69-4007-8c3d-a7068406a031-image.png

      https://boghma.com
      https://github.com/DunHouGo

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

        Hey @Dunhou,

        Thank you for reaching out to us. This subject comes up from time to time, and the answer is that you have to eval the description at runtime. I probably should write a more prominent example for that. In case you have already considered this option and deemed it unsafe, there is no safer route.

        Cheers,
        Ferdinand

        """Demonstrates how to evaluate a dynamically built description at runtime.
        
        Things like cycles (Cinema slang for a combo box) are often built at runtime in Cinema 4D. I.e., 
        there is no resource where one could look up all the cycle elements in advance. And this of course
        makes sense, because something like all the installed render engines cannot be known in advance.
        
        The solution to this to evaluate the description of the item at runtime, to figure out what cycle
        index corresponds to which string label. This is of course a bit unsafe, but there is no better way
        for dynamic elements as their defining characteristics is that they do not have a static identifier.
        """
        
        import c4d
        import mxutils
        
        doc: c4d.documents.BaseDocument  # The currently active document.
        op: c4d.BaseObject | None  # The primary selected object in `doc`. Can be `None`.
        
        def main() -> None:
            """Called by Cinema 4D when the script is being executed.
            """
            # Get the import/export preferences plugin.
            pref: c4d.plugins.BasePlugin = mxutils.CheckType(
                c4d.plugins.FindPlugin(c4d.PREFS_IMPORTEXPORT, c4d.PLUGINTYPE_PREFS))
            
            # Get its description and there the container for `PREF_IMEXPORT_NODESPACE`.
            desc: c4d.Description = pref.GetDescription(c4d.DESCFLAGS_DESC_NONE)
            param: c4d.BaseContainer = mxutils.CheckType(desc.GetParameter(c4d.PREF_IMEXPORT_NODESPACE))
        
            # Get the cycle element in the parameter container and print all values.
            cycle: c4d.BaseContainer = mxutils.CheckType(param[c4d.DESC_CYCLE])
            for i, v in cycle:
                print(f"Cycle element {i}: {v}")
        
            # Build a translation map from string labels to indices. This assumes that there are no exactly
            # identical render engine labels in the cycle. Which is reasonable but not a hard guarantee.
            engineMap: dict[str, int] = {v: i for i, v in cycle}
        
            # Now set the render engine in the settings using a string and a fallback value in case an
            # engine with our string is not present.
            pref[c4d.PREF_IMEXPORT_NODESPACE] = engineMap.get("CentiLeo", 0)
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        DunhouD 1 Reply Last reply Reply Quote 0
        • DunhouD
          Dunhou @ferdinand
          last edited by

          Thanks @ferdinand for your great solution!

          Cheers~
          DunHou

          https://boghma.com
          https://github.com/DunHouGo

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