mardi 1 juin 2021

blender , assign a texture via script with fixed name + variable

here my issue. the script works fine in Blender 2.9 , until I put that random variable in the name. basically I need to link different textures to different files and materials via script . the problem is that I have label 21.jpg, label 34.jpg , label 345.jpg . that "random variable" is a placeholder, what do I need to put there so it succesfully loads the label texture , no matter which random number is in the name? thanks in advance

import bpy
import os
from random import *
from time import gmtime, strftime
import xml.etree.ElementTree as ET 
from bpy.types import Operator
from bpy.props import FloatVectorProperty,StringProperty, IntProperty, BoolProperty, EnumProperty

os.getcwd()

def remap_texture_images():
    color_img = bpy.data.images['color']
    color_img.filepath = bpy.path.relpath("//" + "label" + random_variable + ".jpg")
    
remap_texture_images()



Aucun commentaire:

Enregistrer un commentaire