I am creating a blender plugin to import a file, which also contains path and texture name information.
What im doing in the code, is to try and actually open the path contained in the file, however, what I want to do and I cant, is to get the user to select a new texture path, if the one that was just used is found to be invalid.
#Create Materials
for mtr in material_instance:
mat_name = read_string(strings[0][0][mtr[0]])
mat = bpy.data.materials.new(name=mat_name)
mat.use_nodes = True
nodes = mat.node_tree.nodes
for node in nodes:
nodes.remove(node)
links = mat.node_tree.links
principled = nodes.new(type='ShaderNodeBsdfPrincipled')
node_output = nodes.new(type='ShaderNodeOutputMaterial')
node_output.location = 400,0
link = links.new(principled.outputs[0], node_output.inputs[0])
for tex in range(mtr[4], mtr[4]+mtr[2]):
tex_type = read_string(strings[0][0][texture_type_assignments[tex][0]])
print(tex_type)
image_tex = nodes.new(type='ShaderNodeTexImage')
image_name = read_string(strings[0][0][texture_definitions[texture_type_assignments[tex][1]][0]])
image_path = read_string(strings[0][0][texture_definitions[texture_type_assignments[tex][1]][1]])
if (not os.path.isdir(image_path)):
msg = "Please select a dir for path {0}".format(image_path)
#DO SOMETHING TO GET NEW CUSTOM PATH FROM USER
#image_path = new_path_from_user
image_full_dir = '{0}{1}'.format(image_path,image_name)
try:
image_tex.image = bpy.data.images.load(image_path+image_name.replace('.tga','.dds'), check_existing=True)
except:
image_tex.image = bpy.data.images.new(image_name, 1, 1)
As you can see, I read the -to be imported- image name and path from the file, and then try to see if the path that I just read is valid. However, if it's not, I would like to get the user to select a new one, without of course interrupting the whole importing process (so this new path selection should happen in-between all this, as the files I am trying to import, may contain more than 1 different image paths.
Is that possible?