Guest User

ChangeC4DBitmapToOctaneBitmap

a guest
Jul 14th, 2016
137
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import c4d
  2. #-- Graphos
  3. # visit graphos.fr
  4. ID_C4D_BITMAP = 5833
  5. ID_OCTANE_BITMAP = 1029508
  6.  
  7. def getLinkedData(shader):
  8.     buffer = []
  9.    
  10.     bc = shader.GetDataInstance()
  11.     for i in xrange(0,len(bc)):
  12.         index = bc.GetIndexId(i)
  13.         linked = bc.GetLink(index,doc,c4d.Xbase)
  14.         if linked:
  15.             buffer.append([index,shader,linked])
  16.     return buffer
  17.  
  18. def changeTexture(id,currentShader,enfantShader):
  19.     if enfantShader.CheckType(ID_C4D_BITMAP):
  20.         currentPath = enfantShader[c4d.BITMAPSHADER_FILENAME]
  21.         enfantShader.Remove()
  22.        
  23.         imageTexture = c4d.BaseShader(ID_OCTANE_BITMAP)
  24.         imageTexture[c4d.IMAGETEXTURE_FILE] = currentPath
  25.         currentShader[id] = imageTexture
  26.         currentShader.InsertShader(imageTexture)
  27.        
  28.         currentShader.Message(c4d.MSG_UPDATE)
  29.         c4d.EventAdd()
  30.  
  31. def searchInShader(shader):
  32.     shaderList = getLinkedData(shader)
  33.    
  34.     for i in shaderList:
  35.         changeTexture(i[0],i[1],i[2])
  36.         searchInShader(i[2])
  37.    
  38. def main():
  39.     matList = doc.GetActiveMaterials()
  40.     for mat in matList:
  41.         searchInShader(mat)
  42.  
  43. if __name__=='__main__':
  44.     main()
RAW Paste Data