Jump to content
Sign in to follow this  
Jytheredhood

Batch JPEG to materials

Recommended Posts

Hi all,

 

I am working on several projects where I have to create hundreds of new materials from Diffuse Maps (jpeg).  So for instance "wall_1.jpg" has to go into the diffuse slot of a new material named as "wall_1".  I would really appreciate if anyone could share a script that does the job (or similar), or point me to any thread if it has been posted before.  Thanks!

Share this post


Link to post
Share on other sites

Hi,

here's a small script for use in C4D's Script Manager.

The script lets you choose a folder and will then create one material per image found in that folder (non-recursive).

# For all images in a selected folder create a material
# with the image mapped to the color channel
import os
import c4d

# Add missing image suffixes here, if an image file is not found
IMAGE_SUFFIXES = ('jpg', 'jpeg', 'png', 'tif', 'gif')

def main():
    folder = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, doc.GetDocumentPath(), c4d.FILESELECT_DIRECTORY)
    if folder is None:
        return
    print folder
    folder = folder.replace('\\', '/')
    if folder[-1] != '/':
        folder += '/'
    doc.StartUndo()
    for filename in os.listdir(folder.decode("utf-8")):
        fn = filename.rsplit('.', 1)
        if len(fn) <= 1 or fn[1].lower() not in IMAGE_SUFFIXES:
            continue
        mat = c4d.Material()
        mat.SetName(fn[0])
        shd = c4d.BaseShader(c4d.Xbitmap)
        shd[c4d.BITMAPSHADER_FILENAME] = folder + filename.encode("utf-8")
        mat.InsertShader(shd)
        mat[c4d.MATERIAL_COLOR_SHADER] = shd
        doc.InsertMaterial(mat)
        doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
    doc.EndUndo()
    c4d.EventAdd()    

if __name__=='__main__':
    main()

Hope it helps.
Cheers

 

Edit 22:09: fixed string handling for os functions

Share this post


Link to post
Share on other sites

There is also Image 2 Plane from Pixel Lab. Not only will it import a folder full of images and create a material, but will also create a plane object at the proper proportion and apply that material. Doesn't sound like you need to planes right now, but it's very cool if you do need them. Simply delete the planes and you have your materials. 

Image 2 Plane from PixelLab

 

Edit: Not having used this for a while, now I see you have many more options than I remembered, including a Materials Only button. Very nice.

Screen Shot 2019-11-18 at 12.01.00 PM.png

Share this post


Link to post
Share on other sites

@kbar Yeah, I thought there was a Cineversity tool similar to this, but didn't remember if it was as powerful.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...