THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/10/2011 at 01:41, xxxxxxxx wrote:
Thanks to all. I solved the problem. Here is my final script:
import c4d
from c4d import gui
from c4d import storage
import os
#Welcome to the world of Python
myMaterials = doc.GetMaterials()
fileExtension = ".jpg"
def main() :
pathToTextures = c4d.storage.LoadDialog(0,"Texturpfad wählen",2)
for mat in myMaterials:
name = mat.GetName()
# arrange the new name by replacing
# every `_group` with just nothing ``.
textureName = name
# arrange the new name by replacing
# every `_group` with just nothing ``.
textureName = name.replace( "material_", "texture_" )
# concetenate the path to textures with the name
# of the texture
# we use `os.path` because it adapts the operating
# systems way to deal with pathnames
fullPath = os.path.join( pathToTextures, textureName )
# we need the original texturename, so we add the
# file extension now
fullPath = fullPath + fileExtension
# check if the texture exists
if not os.path.exists( fullPath ) :
# tell that the object could not be associated
# with a texture
print "Texture could not be found:", fullPath
else:
# create a shader for the material
sha = c4d.BaseList2D(c4d.Xbitmap)
sha[c4d.BITMAPSHADER_FILENAME] = fullPath
mat.InsertShader( sha )
mat[c4d.MATERIAL_COLOR_SHADER] = sha
# update the material
mat.Message( c4d.MSG_UPDATE )
mat.Update( True, True )
# update the Cinema 4D UI
c4d.EventAdd()
# tell that the processing was finished
print "Finished processing."
gui.MessageDialog("Finished processing.")
if __name__=='__main__':
main()
But there are two new questions.
1. If I look into the documentation the function GetMaterials is in the namespace c4d.documents.BaseDocument. But if I use this namespace the command could not be found. Why and from where I can know the namespace doc? I got it from the script above.
2. In the documentation for the command LoadDialog is written about constants like FILESELECT_DIRECTORY. But it isn't known by the interpreter. Where are they defined and what I have to import that it works?