0

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.

Here is my code snippet code_snippet

    #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?

Panos Paschalis
  • 171
  • 2
  • 13
  • 1
    please give your code snippet as text, not an image – Artemis Mar 24 '18 at 15:05
  • @ArtemisFowl added it in the question – Panos Paschalis Mar 24 '18 at 17:08
  • Maybe a duplicate from https://stackoverflow.com/questions/15595124/input-dialog-box-blender – progmatico Mar 24 '18 at 17:29
  • @progmatico can't understand how to intergrate that popup code into my code in that position that I specified though. – Panos Paschalis Mar 24 '18 at 18:07
  • Know nothing about blender sorry, but looks like adding something as `bpy.ops.object.dialog_operator('INVOKE_DEFAULT')` will do if you add and adapt the code in your plugin from the popup dialog script here https://wiki.blender.org/index.php/Dev:Py/Scripts/Cookbook/Code_snippets/Interface#A_popup_dialog – progmatico Mar 24 '18 at 19:07

0 Answers0