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

    Texture change python

    PYTHON Development
    0
    5
    716
    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
      Helper
      last edited by

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

      On 26/10/2011 at 08:54, xxxxxxxx wrote:

      Hi there,

      Is there a way to change the texture in the color channel of a material using python.
      Currently i'm writing a script where there is a variable on my clipboard wich is used to build up a document.
      If my question isn't clear, let me know.

      Much thanx in advance.
      Kind regards RNE

      Script so far:

      from c4d import gui, bitmaps, documents
      import c4d
      c4d.StopAllThreads() 
      c4d.StatusSetSpin()
      c4d.StatusSetText("Starting script")
      datanaam = c4d.GetStringFromClipboard()
      c4d.CallCommand(1024314) # Clear Python Log
      c4d.CallCommand(1022604) # Open Python Log

      klaar maken om te renderen

      doc = documents.GetActiveDocument()
      rd = doc.GetActiveRenderData()

      instellen van de rendersettings op basis van de texture

      c4d.StatusSetText("Adjusting render settings")
      currpath=''+rd.GetDataInstance()[c4d.RDATA_MULTIPASS_FILENAME]
      currpath=''+doc[c4d.DOCUMENT_PATH]+'/'
      rd[c4d.RDATA_MULTIPASS_SAVEIMAGE] = 1 # 1=aan 0=uit
      rd[c4d.RDATA_MULTIPASS_FILENAME] = r''+currpath+"Renders/"+datanaam+'.psd'
      c4d.EventAdd()

      #changing the texure

      klaar maken om te renderen

      doc = documents.GetActiveDocument()
      #save the current document as a c4d file
      c4d.documents.SaveDocument(doc, currpath+"CinemaFiles/"+datanaam+".c4d", c4d.SAVEDOCUMENTFLAGS_DIALOGSALLOWED, c4d.FORMAT_C4DEXPORT)

      doc = c4d.documents.GetActiveDocument()
      lijst=c4d.documents.GetBatchRender()
      lijst.AddFile(currpath+"CinemaFiles/"+datanaam+".c4d",0)
      c4d.documents.BatchRender.Open(lijst)
      c4d.StatusSetText("Added to renderlist")
      c4d.documents.CloseAllDocuments()
      c4d.CallCommand(465003513); # start render queue

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

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

        On 26/10/2011 at 18:07, xxxxxxxx wrote:

        The thought process is as follows:
        -Get the material you want to change by whatever means you prefer(if Active, It's name, etc.).
        -Create a new Xbitmap shader to hold your texture image.
        -Tell that Xbitmap shader where to find the texture image using file paths.
        -Insert that Xbitmap shader into the color channel of the material.

        This example will insert the image named "myimage.jpg" from your desktop into the color channel of the currently active material:

        import c4d  
        import os  
          
        def main() :  
          
          fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path  
          pathToTexture = os.path.join(fn,'myimage.jpg')      #Gets the specific texture image on your desktop  
          
          mat = doc.GetActiveMaterial()                       #Assign the active material a variable  
          shdr_texture = c4d.BaseList2D(c4d.Xbitmap)          #Create a bitmap shader in memory  
          shdr_texture[c4d.BITMAPSHADER_FILENAME] = pathToTexture #Assign the path to the texture image to your shader   
          mat[c4d.MATERIAL_COLOR_SHADER]= shdr_texture        #Assign the shader to the color channel in memory only  
          mat.InsertShader(shdr_texture)                      #Insert the shader into the color channel  
          mat.Update(True, True)                              #Re-calculate the thumbnails of the material  
          
        if __name__=='__main__':  
          main()
        

        -ScottA

        1 Reply Last reply Reply Quote 0
        • H
          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 01:50, xxxxxxxx wrote:

          Big thanx ScottA

          Now I can't find any documentation on how to select a material by its name.
          Can you please help me out. mat = doc.GetMaterial doesn't work ?

          Much thanx in advance
          Kind regards RNE

          1 Reply Last reply Reply Quote 0
          • H
            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 03:13, xxxxxxxx wrote:

            Hi,

            To get a material by name, there is doc.SearchMaterial(name).

            1 Reply Last reply Reply Quote 0
            • H
              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 04:22, xxxxxxxx wrote:

              Thanx a lot, this works great.

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