PDA

View Full Version : maybe someone can complete this...


dirtyharry
09-20-2012, 11:14 AM
i would like to write a script to import all textures from a folder onto card with alpha
like the imageplane coffee-script (dont know the author) which works, but only for a single image.

so i have a python-code snippet which asks for the folder and creates materials and more,
but im not a programmer and so not able to finish it and make it work.
heres what i got so far:

import c4d
from c4d import gui
import os

def main():
path=c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Please choose a folder", c4d.FILESELECT_DIRECTORY)
dirList=os.listdir(path)
for fname in dirList:
print fname
c4d.CallCommand(600000042) # Material
mat = doc.GetFirstMaterial()
if mat is None: return False



#mat()[c4d.MATERIAL_USE_ALPHA]=True
#mat()[c4d.MATERIAL_USE_SPECULAR]=False

mat[c4d.ID_BASELIST_NAME]= fname

shd = c4d.BaseList2D(c4d.Xbitmap)

shd[c4d.BITMAPSHADER_FILENAME] = fname




myPlane = c4d.BaseObject(c4d.Oplane)
doc.InsertObject(myPlane)


mat[c4d.MATERIAL_COLOR_SHADER] = shd
mat.InsertShader(shd)
mat[c4d.MATERIAL_ALPHA_SHADER] = shd
mat.InsertShader(shd)

mat[c4d.MATERIAL_USE_ALPHA]=True
mat[c4d.MATERIAL_USE_SPECULAR]=False

#mat.Update(True, True)
#mat.Message(c4d.MSG_UPDATE)


if __name__=='__main__':
main()



the wish-list for this is:

choose a folder
import texture from folder into color and alphachannel
apply to standing plane with height/width same as bitmap in pixels
put pivot on lower end of plane


so please when someone has an idea how to do that would be great....

thanks and
greets dharry

NiklasR
09-21-2012, 07:21 PM
Hello dirtyharry,

I wrote this script (http://pastebin.com/WxG6YDA6) for you in a few mins. I hope it is doing what you search for. When you run it, you wil be asked to select a directory. After that, another window opens, asking you for a glob-patterns. You may know this from Unix systems. Here (http://en.wikipedia.org/wiki/Glob_%28programming%29)'s more about it. You can seperate multiple glob-patterns with a semi-colon (as well as leading and trailing spaces to make it more readable).
The default glob-pattern matches all *.tif and *.tiff files. Note that passing the same pattern two times will import the files matching the pattern two times.

-Niklas

dirtyharry
09-22-2012, 10:27 AM
thanks a lot niklasR, absolutely amazing,
works like a charm

one thing would be great, to make the plane standing (-Z) and set the pivot to the lowest middle
but i´m also very happy with what i got now

Dankeschön

dharry

ernia
09-22-2012, 09:43 PM
VERY useful, Niklas!
Had to do it manually only yesterday.
Thanks!

CGTalk Moderation
09-22-2012, 09:43 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.