我正在创建一个blender插件来导入一个文件,该文件还包含路径和纹理名称信息。
我在代码中做的是尝试实际打开文件中包含的路径,然而,我想要做的事情,我不能,是让用户选择一个新的纹理路径,如果那个刚被使用被发现无效。
#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)
如您所见,我从文件中读取了 - 要导入的图像名称和路径,然后尝试查看我刚刚读取的路径是否有效。但是,如果不是,我想让用户选择一个新的,当然不会中断整个导入过程(所以这个新的路径选择应该发生在所有这些之间,因为我是文件尝试导入,可能包含多个不同的图像路径。
这可能吗?