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

    create a material with a set texture?

    General Talk
    r20 python
    2
    3
    694
    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.
    • JH23J
      JH23
      last edited by

      I had a doubt, I wanted to place an established texture on the material created, but I don't know how, since the textures part is not a simple link type data in itself, but if I link directly where the link of the image is born is a bitmap but I don't know how it relates to the material.

      import c4d
      
      def main():
          mat = c4d.BaseList2D(c4d.Mmaterial)
          doc.StartUndo()
          doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
          doc.InsertMaterial(mat)
          mat[c4d.MATERIAL_USE_REFLECTION] = False
          #mat[c4d.MATERIAL_COLOR_SHADER] ?
          #Bitmap[c4d.BITMAPSHADER_INTERPOLATION]?
          #Bitmap[c4d.BITMAPSHADER_FILENAME]?
          doc.EndUndo()
          c4d.EventAdd()
      
      # Execute main()
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hi,

        The code below will show you how to do that. You must instantiate and insert a Xbitmap shader in your material. In that shader, you can define the texture path.

        import c4d
        
        def main():
            texturePath = "C:\\texture.jpg"
            
            # Creates the new material
            mat = c4d.BaseList2D(c4d.Mmaterial)
            # Start the undo stack
            doc.StartUndo()
            doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
            # Insezrt the material into the document
            doc.InsertMaterial(mat)
            mat[c4d.MATERIAL_USE_REFLECTION] = False
            
            # Create a new bitmap Shader.
            bitmapShader = c4d.BaseShader(c4d.Xbitmap)
            # Define the filename for the bitmap shader
            bitmapShader[c4d.BITMAPSHADER_FILENAME] = texturePath
            
            # Set the material color paratemer.
            mat[c4d.MATERIAL_COLOR_SHADER] = bitmapShader
            
            # Insert the shader in the material's shader list
            mat.InsertShader(bitmapShader)
        
            # End the undo stack
            doc.EndUndo()
            
            # Pushes an update event to Cinema 4D
            c4d.EventAdd()
        
        # Execute main()
        if __name__=='__main__':
            main()
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • JH23J
          JH23
          last edited by

          Hi.
          Oh I understand, thanks for your answer, it has helped me a lot.

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