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

    Setting Material Preview for 1 material

    Cinema 4D SDK
    2023 python
    2
    3
    522
    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.
    • P
      pim
      last edited by

      I know it is possible to set the material preview in Preferences by
      Material[c4d.PREF_MM_MATSCENE] = 2000001008 #Flat projection

      When I try to do this for a single material, it is not working.
      What am I doing wrong?

      from typing import Optional
      import c4d
      
      doc: c4d.documents.BaseDocument # The active document
      op: Optional[c4d.BaseObject] # The active object, None if unselected
      
      def main() -> None:
          mat = doc.GetActiveMaterial()
          print (mat.GetName(), mat[c4d.PREF_MM_MATSCENE])
          mat[c4d.PREF_MM_MATSCENE] = 2000001008    #Flat projection
          mat.Update(True, True)
      
      if __name__ == '__main__':
          main()
          c4d.EventAdd()
      

      PS How can I set a post to 'Solved"?

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by Manuel

        Hi,

        If you want to change the default material preview scene, the one in the preferences, you must do the following.

            wc = c4d.GetWorldContainerInstance()
            wc[c4d.WPREF_MATPREVIEW_DEFAULTOBJECT_MAT] = c4d.MatPreviewSphere
        

        The ID that needs to be used can be found here. We have a code that will add 2000000000 to this value if the value is lower than MatPreviewUser (1050). If i remember correctly, users were able to add their own scene preview. With the nodematerial this is not possible anymore.

        If you want to change the material preview of a standard material, you must retrieve the material preview data of the material. Unfortunately, this DataType is not implemented in python so this is not possible.

        It is possible to change the value of this preview in the preferences and create the material, but it doesn't work if you set back the value that was defined.

        from typing import Optional
        import c4d
        
        doc: c4d.documents.BaseDocument # The active document
        op: Optional[c4d.BaseObject] # The active object, None if unselected
        
        def main() -> None:
        
            wc = c4d.GetWorldContainerInstance()
            saveValue  = wc[c4d.WPREF_MATPREVIEW_DEFAULTOBJECT_MAT]
            wc[c4d.WPREF_MATPREVIEW_DEFAULTOBJECT_MAT] = c4d.MatPreviewSphere
            
               
            material = c4d.BaseMaterial(c4d.Mmaterial)
            doc.InsertMaterial(material)
        
            # this line will make the material preview modification not working
            # wc[c4d.WPREF_MATPREVIEW_DEFAULTOBJECT_MAT] = saveValue
            c4d.EventAdd()
        
        if __name__ == '__main__':
            main()
            c4d.EventAdd()
        

        The question about marking a thread as solved, you can have a look at our forum guidelines

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • P
          pim
          last edited by

          Thank you.

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