2010-11-17 07:00:14 +00:00
|
|
|
import bpy
|
|
|
|
|
2011-01-26 07:54:27 +00:00
|
|
|
|
2010-11-17 07:00:14 +00:00
|
|
|
def write_some_data(context, filepath, use_some_setting):
|
|
|
|
print("running write_some_data...")
|
2012-04-17 05:47:32 +00:00
|
|
|
f = open(filepath, 'w', encoding='utf-8')
|
2024-04-12 05:33:40 +00:00
|
|
|
f.write("Hello World {:s}".format(use_some_setting))
|
2010-11-17 07:00:14 +00:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
# ExportHelper is a helper class, defines filename and
|
|
|
|
# invoke() function which calls the file selector.
|
2011-05-16 07:51:02 +00:00
|
|
|
from bpy_extras.io_utils import ExportHelper
|
2011-02-27 15:25:24 +00:00
|
|
|
from bpy.props import StringProperty, BoolProperty, EnumProperty
|
2012-04-17 05:47:32 +00:00
|
|
|
from bpy.types import Operator
|
2010-11-17 07:00:14 +00:00
|
|
|
|
|
|
|
|
2012-04-17 05:47:32 +00:00
|
|
|
class ExportSomeData(Operator, ExportHelper):
|
2012-07-01 07:55:44 +00:00
|
|
|
"""This appears in the tooltip of the operator and in the generated docs"""
|
2012-04-17 05:47:32 +00:00
|
|
|
bl_idname = "export_test.some_data" # important since its how bpy.ops.import_test.some_data is constructed
|
2010-11-17 07:00:14 +00:00
|
|
|
bl_label = "Export Some Data"
|
2011-01-26 07:54:27 +00:00
|
|
|
|
2023-09-05 00:49:20 +00:00
|
|
|
# ExportHelper mix-in class uses this.
|
2010-11-17 07:00:14 +00:00
|
|
|
filename_ext = ".txt"
|
|
|
|
|
2018-07-11 20:18:09 +00:00
|
|
|
filter_glob: StringProperty(
|
2018-06-26 17:41:37 +00:00
|
|
|
default="*.txt",
|
|
|
|
options={'HIDDEN'},
|
|
|
|
maxlen=255, # Max internal buffer length, longer would be clamped.
|
|
|
|
)
|
2010-11-17 07:00:14 +00:00
|
|
|
|
|
|
|
# List of operator properties, the attributes will be assigned
|
|
|
|
# to the class instance from the operator settings before calling.
|
2018-07-11 20:18:09 +00:00
|
|
|
use_setting: BoolProperty(
|
2018-06-26 17:41:37 +00:00
|
|
|
name="Example Boolean",
|
|
|
|
description="Example Tooltip",
|
|
|
|
default=True,
|
|
|
|
)
|
2011-08-19 19:25:20 +00:00
|
|
|
|
2018-07-11 20:18:09 +00:00
|
|
|
type: EnumProperty(
|
2018-06-26 17:41:37 +00:00
|
|
|
name="Example Enum",
|
|
|
|
description="Choose between two items",
|
|
|
|
items=(
|
|
|
|
('OPT_A', "First Option", "Description one"),
|
|
|
|
('OPT_B', "Second Option", "Description two"),
|
|
|
|
),
|
|
|
|
default='OPT_A',
|
|
|
|
)
|
2010-11-17 07:00:14 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
return write_some_data(context, self.filepath, self.use_setting)
|
|
|
|
|
|
|
|
|
|
|
|
# Only needed if you want to add into a dynamic menu
|
|
|
|
def menu_func_export(self, context):
|
|
|
|
self.layout.operator(ExportSomeData.bl_idname, text="Text Export Operator")
|
|
|
|
|
2022-04-20 05:11:22 +00:00
|
|
|
|
|
|
|
# Register and add to the "file selector" menu (required to use F3 search "Text Export Operator" for quick access).
|
2011-02-12 08:04:32 +00:00
|
|
|
def register():
|
|
|
|
bpy.utils.register_class(ExportSomeData)
|
2018-08-29 13:02:21 +00:00
|
|
|
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
|
2011-02-12 08:04:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
bpy.utils.unregister_class(ExportSomeData)
|
2018-08-29 13:02:21 +00:00
|
|
|
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
|
2011-02-12 08:04:32 +00:00
|
|
|
|
2010-11-17 07:00:14 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2011-02-12 08:04:32 +00:00
|
|
|
register()
|
|
|
|
|
|
|
|
# test call
|
2012-04-17 05:47:32 +00:00
|
|
|
bpy.ops.export_test.some_data('INVOKE_DEFAULT')
|