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

    Duplicating Materials

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 350 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 27/10/2011 at 11:52, xxxxxxxx wrote:

      Hey guys.
      I'm trying to get my head around this:
      I need to duplicate Materials and keep their alpha channels and just get rid of everything else.
      As I didn't find an option for just duplicating materials I just created new materials and wanted to copy the content from the active material to the new one.
      I did this by using BaseList2D.GetData() and BaseList2D.SetData() -> didn't work.
      So I thought of the neat BaseContainer.CopyTo() function -> the material gets duplicated, but shaders are not ... at least not in a way they are working correctly (they seem to be linked to the old material and just don't render).
      Again no problem, I just duplicate the shaders. Same problem here but with an Error message:
      "free render called illegaly - application stability affected"
      or sometimes something about "found more than one object. try inserting one at time"
      ... interesting.
      So my question is: is there an easy way to clone/duplicate materials AND their shaders (because only materials doesn't seem to work).
      This is the last script I used:
      def main() :
         oldmat = doc.GetActiveMaterial()
         newmat = c4d.BaseMaterial(oldmat.GetType())
         shd = c4d.BaseList2D(oldmat[c4d.MATERIAL_ALPHA_SHADER].GetType())
         oldmat[c4d.MATERIAL_ALPHA_SHADER].CopyTo(shd,1)
         newmat[c4d.MATERIAL_ALPHA_SHADER] = shd
         newmat.InsertShader(shd)
         doc.InsertMaterial(newmat)

      if __name__=='__main__':
      main()
      Hopefully someone can help
      thanx
      Phil

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 28/10/2011 at 02:07, xxxxxxxx wrote:

        You can use GetClone() to get a complete copy of a material:

        import c4d
          
        def main() :
           mat = doc.GetActiveMaterial()
           copy = mat.GetClone()
           
           print mat
           print mat[c4d.MATERIAL_ALPHA_SHADER]
           
           print copy
           print copy[c4d.MATERIAL_ALPHA_SHADER]
          
          
        if __name__=='__main__':
            main()
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 28/10/2011 at 05:26, xxxxxxxx wrote:

          Thanx a lot that's it, works like a charm.
          cheers
          Phil

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