On 29/05/2015 at 12:24, xxxxxxxx wrote:
I don't know python at all but I'm trying to figure out how to automate part of a process for a job I'm working on.
My goal is to load images from the "tex" folder into the color channel of the material on my object, keyframe it, move to the next image, then next frame, keyframe, etc., until all images in that folder have a keyframe on the same material. I've been doing it by hand for this job for folders with 160 images and making mistakes, and now the job requires me to do that for folders much larger! ARgh!
I know you can use the animate function on a material to pull a folder of images but it doesn't import the image path nor does it create an actual keyframe which I need for my project to work correctly.
I've been pulling python code from various places and trying to toy around and get something to work but I just lack the knowledge and experience. Had I more time I could maybe flesh it out but as I don't have a ton of time I am turning to you :-)
I found this code that loads an image from the desk top. It seems to work but I can't seem to change the path to, say, the tex folder in my job....but on top of that I need it to do more.
def main() :
fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path
pathToTexture = os.path.join(fn,'01.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
I've also pulled some other code that might get the job done but I am not sure how to implement it.
imageList = os.listdir(folder) # get folder contents frame = document.GetFrame() # determin the current frame offset = 0 # define frame offset frameOffset = frame+offset # calculate the offset material[c4d.imageSlot] = imagelist[frameOffset] # set image in material Any help would be greatly appreciated.