1
$\begingroup$

What I'm after here is to give the user the freedom to either search for a missing image texture via file selector or replace it with a dummy image stored in the addon folder.

enter image description here

This is what I'm attempting to do:

class FixMe(bpy.types.Operator):
    """Find or replace missing image texture"""
    bl_idname = "object.fix_me"
    bl_label = "Fix Me"

    file_: bpy.props.StringProperty(name= "Image File", subtype='FILE_PATH')
    replace: bpy.props.BoolProperty(name= "Replace with a dummy image", default= False)

    def execute(self, context):
        print("Selected image is")
        print(self.file_)

        return {'FINISHED'}

    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self)

    def draw(self, context):
        layout = self.layout
        col = layout.column()
        col.label(text= "Replace image")
        sub = col.column()
        sub.prop(self, "file_")
        if self.replace:
            sub.enabled = False
        col.prop(self, "replace")

I'm trying to get the selected file path using self.file_ but sounds that all the code in execute() does not run at all and an error find_node_operation: Failed for (DRIVER, 'cycles.seed') shows up in the console.

Adding Replace with a dummy image as an ImportHelper property will make the interface less intuitive, the user should be able to select that option in a single click rather than open a file browse window to do.

I'm aware that I can do that via Panels and Properties, but this will not fit into the use case I'm after in this particular situation.

$\endgroup$

1 Answer 1

0
$\begingroup$

Well, I've come up with a dirty workaround, by creating a new ImportHelper operator and added it to the menu. I couldn't think of a smarter approach that's why I'm not marking the answer as the correct answer.

enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .