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

    Python replace Textures Help / advice

    Scheduled Pinned Locked Moved PYTHON Development
    1 Posts 0 Posters 146 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 06/06/2013 at 03:15, xxxxxxxx wrote:

      Ola,

      i'm facing a challenge and crunching trough it.  im a python starter but i like it.

      What im trying to do is to replace all the textures paths in my scene (Materials setup : color channel -> multishader with 10 videoclips in it) in all Materials in the scenefile.

      Here is the catch.
      im replacing the low mp4 with an image sequence with it respectful folder. the thing that changes is basepath\imageseq_name\imageseq_name_00000.jpg where for every file there is another name (namex_00000.jpg in folder namex) which replaces basepath\allstuf\namex.mp4

      Hope you understand what im trying to achieve.
      For now i managed to do all the above except getin trough to multishader to replace the respective paths, otherwise im creating all new materials for every mp4 which gets replaced in multishader (located in color chan).

      Here is my working script, please do not bithc me out im still learnin and its very fun, hope i can manage to do some more complex things in the future.
      ---------------------

      import c4d
      from c4d import gui, bitmaps, documents, storage
      import os
      from os.path import basename, splitext
      import re

      print "------------ Starting"
      #c4d.StopAllThreads()

      def main() :
          myMaterials       = doc.GetAllTextures()
          myTexture = c4d.BITMAPSHADER_FILENAME
          fileExtensionWrong   = ".mp4"
          fileExtension   = "_00000.jpg"
          path1 = r'E:\global new\assests frames' #set ur paths
          path2 = r'E:\global new\assets' #set ur paths
          # insert the path to the directory of interest
          newPath = path1 + fileExtension
          #print newPath   
          #print myTexture

      #print(myMaterials)
          for (i,item) in myMaterials:
              print "old item: "+item
              newitem=item.replace ( '.mp4' , '_00000.jpg' )
              newitem2=newitem.replace ( path2,'')
              #newitem3=newitem.replace ( '.mp4','' )
              newName=newitem2.replace ("\",'')
              folderName=newName.replace('_00000.jpg','')
              print "New name is: " + newName
              print "------------------"
              #print newitem2
              print "--- replacing ---"
              newTexturePath = path1 + '\' + folderName + '\' + newName
              print "New texture path is: " + newTexturePath
              myTexture = newTexturePath
              print "code start"
              # Setup and add
              fps=30
              #minFrame=0
              #maxFrame=650 
              doc.SetFps(fps)
              #doc.SetMinTime(c4d.BaseTime(minFrame,fps))
              #doc.SetMaxTime(c4d.BaseTime(maxFrame,fps))
              #doc.SetTime(c4d.BaseTime(maxFrame,fps))
              
              # Materials:[c4d.BITMAPSHADER_TIMING_TO]
              #if not mat: return True
              oldTime=c4d.BITMAPSHADER_TIMING_TO
              print oldTime
              newTime= (oldTime - 1)
              mat = c4d.BaseMaterial(c4d.Mmaterial)
              shader = c4d.BaseShader(c4d.Xbitmap)
              shader[c4d.BITMAPSHADER_FILENAME] = newTexturePath
              shader[c4d.BITMAPSHADER_TIMING_TO]= newTime
              mat[c4d.MATERIAL_COLOR_SHADER] = shader
              print newTime
              mat.InsertShader(shader)
              print "check"
              print shader
              print mat
              mat.Message(c4d.MSG_UPDATE)
              mat.Update
              c4d.EventAdd()
              doc.InsertMaterial(mat)
              #return (mat, shader)

      # print path
          #dirLister=os.listdir(path)
          #for fname in dirLister:
          #    print fname
          #    print myMaterials
          #print myTexture

      # update the Cinema 4D UI
          #c4d.EventAdd()

      # tell that the processing was finished
          print " ------------ Finished processing.-----------------"                
          # gui.MessageDialog("Finished processing.")

      if __name__=='__main__':

      main()
          
          
      print "------------ Done."

      Thanks for any help!

      Des

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