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
    • Recent
    • Tags
    • Users
    • Login

    One material type to another [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 229 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 07/07/2016 at 15:12, xxxxxxxx wrote:

      Here I have a somewhat basic script that takes all materials and creates c4d materials based on their names. What I really want to do is actaully create and replace all the scene with c4d ones. Useful for situations where I find myself needing to convert other render engine materials to basic ones for export. I of course get the creating part, how can I do the conversion? As it stands I run this script and then have to do alt dragging to manually replace my original materials.

      import c4d
      from c4d import gui
        
      def main() :
          mats = doc.GetMaterials();
          
          for mat in mats:
              new_mat = c4d.BaseMaterial(c4d.Mmaterial); # create standard material
              new_mat[c4d.ID_BASELIST_NAME] = mat.GetName() +"_c4d";
              doc.InsertMaterial(new_mat,pred=None,checknames=True)
              
              c4d.EventAdd();
        
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 08/07/2016 at 01:19, xxxxxxxx wrote:

        Hello,

        in Cinema 4D materials are assigned to objects using a Texture Tag. This texture tag is assigned to the object and references the used material through a BaseLink parameter. So you have to change this BaseLink on the texture tag.

        The easiest way to change the BaseLinks is to use BaseList2D.TransferGoal() on the original material with the new material as an argument. This function changes all BaseLinks referencing the given original material.

        Best wishes,
        Sebastian

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

          On 09/07/2016 at 12:29, xxxxxxxx wrote:

          That works like a dream. Thanks.

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