4
def read_some_data(context, filepath, use_some_setting):
5
print("running read_some_data...")
6
f = open(filepath, 'r', encoding='utf-8')
10
# would normally load the data here
16
# ImportHelper is a helper class, defines filename and
17
# invoke() function which calls the file selector.
18
from bpy_extras.io_utils import ImportHelper
19
from bpy.props import StringProperty, BoolProperty, EnumProperty
20
from bpy.types import Operator
23
class ImportSomeData(Operator, ImportHelper):
24
"""This appears in the tooltip of the operator and in the generated docs"""
25
bl_idname = "import_test.some_data" # important since its how bpy.ops.import_test.some_data is constructed
26
bl_label = "Import Some Data"
28
# ImportHelper mixin class uses this
31
filter_glob = StringProperty(
36
# List of operator properties, the attributes will be assigned
37
# to the class instance from the operator settings before calling.
38
use_setting = BoolProperty(
39
name="Example Boolean",
40
description="Example Tooltip",
46
description="Choose between two items",
47
items=(('OPT_A', "First Option", "Description one"),
48
('OPT_B', "Second Option", "Description two")),
52
def execute(self, context):
53
return read_some_data(context, self.filepath, self.use_setting)
56
# Only needed if you want to add into a dynamic menu
57
def menu_func_import(self, context):
58
self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator")
62
bpy.utils.register_class(ImportSomeData)
63
bpy.types.INFO_MT_file_import.append(menu_func_import)
67
bpy.utils.unregister_class(ImportSomeData)
68
bpy.types.INFO_MT_file_import.remove(menu_func_import)
71
if __name__ == "__main__":
75
bpy.ops.import_test.some_data('INVOKE_DEFAULT')