I want to know how to open File open window and I want to know also how to store those selected file names.
bpy.context.window_manager.fileselect_add(), but you can also use the Import template / ImportHelper class.
You need to add certain properties, they will be set by blender if present:
WindowManager.fileselect_add(operator)
Opens a file selector with an operator. The string properties ‘filepath’, ‘filename’, ‘directory’ and a ‘files’ collection are assigned when present in the operator
import bpy
# ImportHelper is a helper class, defines filename and
# invoke() function which calls the file selector.
from bpy_extras.io_utils import ImportHelper
from bpy.props import StringProperty, CollectionProperty
from bpy.types import Operator
class ImportSomeData(Operator, ImportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "import_test.some_data" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Import Some Data"
# ImportHelper mixin class uses this
filename_ext = ".txt"
filter_glob = StringProperty(
default="*.txt",
options={'HIDDEN'},
)
filename = StringProperty(maxlen=1024)
directory = StringProperty(maxlen=1024)
files = CollectionProperty(type=bpy.types.PropertyGroup)
def execute(self, context):
print("-" * 20)
print("Filename (active file):")
print(" ", end="")
print(self.filename)
print()
print("Filepath (active file):")
print(" ", end="")
print(self.filepath)
print()
print("Directory (of files):")
print(" ", end="")
print(self.directory)
print()
print("Files (selected):")
for file in self.files:
print(" ", end="")
print(file.name)
return {'FINISHED'}
# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator")
def register():
bpy.utils.register_class(ImportSomeData)
bpy.types.INFO_MT_file_import.append(menu_func_import)
def unregister():
bpy.utils.unregister_class(ImportSomeData)
bpy.types.INFO_MT_file_import.remove(menu_func_import)
if __name__ == "__main__":
register()
# test call
bpy.ops.import_test.some_data('INVOKE_DEFAULT')
Thank you CoDEmanX, your code will be part of script which renders alpha reflection passes, selected files are reflections texture source.