Losing my Blender flower on this one :)
I'm using an operator to select the filepath of a .txt file.
import bpy
class SelectTxtFile(bpy.types.Operator):
bl_idname = "file.select_txt"
bl_label = "Select TXT File"
bl_options = {"REGISTER", "UNDO"}
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
filter_glob: bpy.props.StringProperty(default="*.txt", options={"HIDDEN"})
def execute(self, context):
print(self.filepath)
return {"FINISHED"}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}
def register():
bpy.utils.register_class(SelectTxtFile)
if name == "main":
register()
bpy.ops.file.select_txt('INVOKE_DEFAULT')
I don't want the user to be able to validate the operator (Blue button) if the file they selected isn't a valid .txt file.
I want the button to be clickable only when :
- The user selected a file and it exists : os.path.isfile(path) returns
True - The extension is .txt : os.path.splitext(path) returns
".txt"
I would like to insert this line somewhere :
layout.enabled = os.path.isfile(self.filepath) and os.path.splitext(self.filepath)[1] == ".txt"
I'd like it to be grayed out if the conditions are not met. But I can't access this particular layout button because it's apparently managed by the window manager.
How can I achieve that ?

need_activeparameter Maybe related https://blender.stackexchange.com/a/207665/15543 – batFINGER Jul 28 '21 at 17:02wm.fileselect_addwhich AFAIK invokes the filebrowser to run modally and appends the footer. Highly recommendpathliboveros.pathshenanigans – batFINGER Jul 29 '21 at 11:11