Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    C4D Material Builder

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 497 Views
    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.
    • H Offline
      Helper
      last edited by

      On 19/11/2017 at 19:33, xxxxxxxx wrote:

      Hey!

      I'm writing a simple script that creates and sets up a C4D Material based on a folder of .jpgs with appropriate "*_diffuse.jpg", "*_specular.jpg" etc. names.

      I've figured out how to create a material, but I'm stuck on how to add the filepath to a ".jpg" to the [c4d.MATERIAL_COLOR_SHADER].

      Create new C4D Material

      c4d.CallCommand(13015, 13015) # New Material
      
      
      # Get First Material, the one we just created
      material = doc.GetFirstMaterial()
      
      
      # rename: cdmat-"name"
      material[c4d.ID_BASELIST_NAME] = "name"
      
      
      # Enable Color Mat[c4d.MATERIAL_USE_COLOR]
      material.SetChannelState(c4d.CHANNEL_COLOR, True)
      
      
      # Set Mat[c4d.MATERIAL_COLOR_SHADER] to name_diffuse.jpg
      material[c4d.MATERIAL_COLOR_SHADER] = "D:\CD-Scenes\008-BedroomDemo\008-Bedroom-01.jpg"
      print(material[c4d.MATERIAL_COLOR_SHADER])
      

      Thanks!

      Matt

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 19/11/2017 at 20:27, xxxxxxxx wrote:

        you need to do like this

            material = c4d.BaseMaterial(c4d.Mmaterial)
            material.SetName("Name")
            # Set the state of a channel
            material[c4d.MATERIAL_USE_COLOR] = True
            # Create Bitmap Shader
            shader = c4d.BaseShader(c4d.Xbitmap)
            shader[c4d.BITMAPSHADER_FILENAME]= r"D:\CD-Scenes\008-BedroomDemo\008-Bedroom-01.jpg"
            # Inserts a shader in the objects shader list
            material.InsertShader(shader)
            material[c4d.MATERIAL_COLOR_SHADER] = shader
            # Inserts Material in Project
            doc.InsertMaterial(material)
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 20/11/2017 at 06:14, xxxxxxxx wrote:

          Hi Matt,

          if you are interested in a bit more background, what anion did in his code and why, you may want to visit the C++ Docs (no worries!) :
          BaseShader Manual
          Material Manual

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