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

    remove old shader

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 525 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 25/05/2017 at 22:34, xxxxxxxx wrote:

      For the material, I create a shader.

      mat = doc.GetActiveMaterial()
      shd1 = c4d.BaseShader(c4d.Xbitmap)
      shd1[c4d.BITMAPSHADER_FILENAME]= FILE_NAME1
      mat.InsertShader(shd1)
      mat[c4d.MATERIAL_DIFFUSION_SHADER] = shd1

      shd1 after I overwrite shd2.

      shd2 = c4d.BaseShader(c4d.Xbitmap)
      shd2[c4d.BITMAPSHADER_FILENAME]= FILE_NAME2
      mat.InsertShader(shd1)
      mat[c4d.MATERIAL_DIFFUSION_SHADER] = shd2

      Is the shd1 removed or is it in memory?

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

        On 26/05/2017 at 03:08, xxxxxxxx wrote:

        Hi,

        shd1 is still in memory. To remove it from the material's shader list after it's been overwriten, call shd1.Remove().
        Assigning a shader to MATERIAL_DIFFUSION_SHADER only set a link to the shader.

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

          On 26/05/2017 at 03:14, xxxxxxxx wrote:

          How can I remove all unused shaders?

          mat.GetFirstShader()
          while(shd) :
              shd.Remove()
              shd = mat.GetFirstShader()

          But this will remove all the shaders of the material including the required ones

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

            On 30/05/2017 at 02:48, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            How can I remove all unused shaders?

            What do you mean by "unused shaders"? The shaders that you have inserted yourself into the material and that are no longer linked?

            To find such unused shaders, you can check the used and assigned channels of the material for each shader in its shader list (returned by GetFirstShader()). If a shader is found then it is used, otherwise it can be removed.

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