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
    • Register
    • Login

    python script change Redshift setting

    Cinema 4D SDK
    python windows 2024
    3
    6
    327
    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.
    • R
      RTF
      last edited by

      I want to write a script to set the Settings of Redshift Matpreview
      But

      import c4d
      import c4d.documents
      import redshift
      import os
      
      
      def FindVideoPost(renderData, pluginId):
          vp = renderData.GetFirstVideoPost()
          while vp is not None:
              if vp.IsInstanceOf(pluginId):
                  return vp
              vp = vp.GetNext()
          return None
      
      def FindAddVideoPost(renderData, vpPluginID):
          vp = FindVideoPost(renderData, vpPluginID)
          if vp is None:
              vp = c4d.documents.BaseVideoPost(vpPluginID)
              if vp is not None:
                  renderData.InsertVideoPost(vp)
          return vp
      
      def main():
          doc = c4d.documents.GetActiveDocument()
          renderdata = doc.GetActiveRenderData()
      
          vprs = FindAddVideoPost(renderdata, redshift.VPrsrenderer)
          if vprs is None:
              return
      
          # Switch renderer
          renderdata[c4d.RDATA_RENDERENGINE] = redshift.VPrsrenderer
      
          # Set Redshift render parameters
          vprs[c4d.PREFS_REDSHIFT_MATPREVIEW_MODE] = 1
      
          # Refresh UI
          c4d.EventAdd()
          # print("Render settings updated to 4K and frame range set to All Frames.")
      
      # Execute the main function
      if __name__=='__main__':
          main()
      

      vprs[c4d.PREFS_REDSHIFT_MATPREVIEW_MODE] = 1
      This code doesn't seem to have any effect

      Then I changed the method and set the code in C4D

      import c4d
      from c4d import gui
      
      def set_amlimit_preference():
          # 获取全局设置容器
          bc = c4d.GetWorldContainerInstance()
      
          # 设置新的值为 666
          bc[c4d.PREFS_REDSHIFT_MATPREVIEW_MODE] = 1
          
          # 应用修改后的设置
          c4d.SetWorldContainer(bc)
      
          # 保存设置到磁盘
          c4d.SaveWorldPreferences()
      
          # 尝试刷新界面
          c4d.EventAdd()
      
      
      # 运行函数
      if __name__ == '__main__':
          set_amlimit_preference()
      

      Can not be modified successfully

      Can someone help me

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

        Hi @RTF , the c4d.PREFS_REDSHIFT_MATPREVIEW_MODE doesn't seem stored in Redshift VideoPost, is this code generated by GPT or something similar?

        Back to the topic, this parameter is stored in the Redshift tab of the preferences node. You should get the redshift preference node and then set the parameter.

        If you installed Renderer lib or boghma hub, you can use this:

        import c4d
        from Renderer import Redshift
        
        if __name__ == '__main__':
            Redshift.SetMaterialPreview(preview_mode = 1)
        

        or just few codes:

        import c4d
        
        ID_PREFERENCES_NODE = 465001632 # Prefs ID
        
        def GetPreference() -> c4d.BaseList2D:
            """
            Get the Redshift preferenc.
            """
            prefs: c4d.plugins.BasePlugin = c4d.plugins.FindPlugin(ID_PREFERENCES_NODE)
            if not isinstance(prefs, c4d.BaseList2D):
                raise RuntimeError("Could not access preferences node.")
              
            descIdSettings = c4d.DescID(
            c4d.DescLevel(1036220, 1, 465001632), # pref ID Redshift
            c4d.DescLevel(888, 133, 465001632)
            )
            return prefs[descIdSettings]
        
        if __name__ == '__main__':
            redshift_pref: c4d.BaseList2D = GetPreference()
            redshift_pref[c4d.PREFS_REDSHIFT_MATPREVIEW_MODE] = 1
        

        Cheers~
        DunHou

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

        R 1 Reply Last reply Reply Quote 2
        • R
          RTF @Dunhou
          last edited by

          @Dunhou
          Thank you for your help, but after I run the following code, the Redshift Settings have not changed
          By the way I am a python novice and the above code is written by GPT
          I just want to use the script to change the Settings of the image below
          358cb6fc-db66-4fdd-94bc-7684b2223966-image.png

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

            you need to change the id of you want

            PREFS_REDSHIFT_MATPREVIEW_MODE_BACKGROUND: int = 3
            PREFS_REDSHIFT_MATPREVIEW_MODE_IDLE: int = 1
            PREFS_REDSHIFT_MATPREVIEW_MODE_OFF: int = 0
            PREFS_REDSHIFT_MATPREVIEW_MODE_SUSPEND: int = 2
            

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

            R 1 Reply Last reply Reply Quote 0
            • i_mazlovI
              i_mazlov @RTF
              last edited by i_mazlov

              Hello @RTF,

              Welcome to the Maxon developers forum and its community, it is great to have you with us!

              Getting Started

              Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.

              • Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
              • Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
              • Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.

              It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.

              About your First Question

              The second way that @Dunhou (thank you for being an active part of our community!) has suggested for you is actually the recommended one. The only missing part is executing c4d.EventAdd() in the end, which is likely the reason why you don't see any changes after running the script.

              If you'd like to get more explanation on this code, please check this great example code posted by Ferdinand: Python: How to get axis scale from the preference settings?

              Cheers,
              Ilia

              MAXON SDK Specialist
              developers.maxon.net

              1 Reply Last reply Reply Quote 0
              • R
                RTF @Dunhou
                last edited by

                @Dunhou @i_mazlov
                Thanks a lot.😊 😊 😊

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