1
$\begingroup$

I'm working on a script to export .stl files with different UV textures based on a list from a specific folder.

After several modifications, i was able to export .stl but the texture is not applied.

My code :

    import bpy
    import os,sys
    import glob
    
    from os import listdir
    from os.path import isfile, join, basename
    
    
    textureDirectory = 'C:\\Users\\username\\Desktop\\_TEXTURES\\'
    exportDirectory = 'C:\\Users\\username\\Desktop\\'
    currentTexture = [os.path.join(textureDirectory, texture) for texture in os.listdir(textureDirectory) if os.path.isfile(os.path.join(textureDirectory, texture))]
    currentFilename = [os.path.join(exportDirectory, filename).split('.')[0] for filename in os.listdir(textureDirectory) if os.path.isfile(os.path.join(textureDirectory, filename))]
    

        for cT, cF in zip(currentTexture, currentFilename) :
        print (cT, cF)
        bpy.ops.image.open(filepath=cT, directory=textureDirectory, files=[{"name":cF+'.png',"name":cF+'.png'}], show_multiview=False)
        bpy.data.images[cF+'.png'].name = cF+'.png'
        bpy.ops.object.select_all(action='SELECT')
        bpy.ops.export_mesh.stl(filepath= exportDirectory + cF + ".stl", check_existing=True, filter_glob="*.stl", use_selection=True, global_scale=1.0, use_scene_unit=False, ascii=False, use_mesh_modifiers=True, batch_mode="OFF", axis_forward="Y", axis_up="Z")

currentTexture : give a full path of the .png file. (e.g.: c:\Users\username\Desktop\myfile.png) currentFilename : give the filename without path and .ext (e.g: myfile)

Do you have an idea, where i'm wrong ?

Thank you

$\endgroup$
1

0

You must log in to answer this question.

Browse other questions tagged .