Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- from bpy_extras.io_utils import ExportHelper
- class ExportFoobar(bpy.types.Operator, ExportHelper):
- bl_idname = "export_scene.foobar"
- bl_label = 'Export Foobar'
- bl_options = {'PRESET'}
- filename_ext = ''
- filter_glob: bpy.props.StringProperty(default='*.foo;*.bar', options={'HIDDEN'})
- extension: bpy.props.EnumProperty(
- name='Extension',
- items=(('FOO', '.foo', '.foo'), ('BAR', '.bar', '.bar')),
- default='FOO',
- )
- def execute(self, context):
- print(self.filepath)
- return {'FINISHED'}
- def check(self, context):
- print('check called')
- import os
- changed = False
- filepath = self.filepath
- if os.path.basename(filepath):
- filepath = bpy.path.ensure_ext(
- filepath,
- '.foo' if self.extension == 'FOO' else '.bar',
- )
- changed = (filepath != self.filepath)
- self.filepath = filepath
- return changed
- def draw(self, context):
- pass
- # NOTE!: if the prop is drawn here instead of in a panel, check is
- # called automatically without having to do anything special
- class FOOBAR_PT_export_main(bpy.types.Panel):
- bl_space_type = 'FILE_BROWSER'
- bl_region_type = 'TOOL_PROPS'
- bl_label = ""
- bl_parent_id = "FILE_PT_operator"
- bl_options = {'HIDE_HEADER'}
- @classmethod
- def poll(cls, context):
- sfile = context.space_data
- operator = sfile.active_operator
- return operator.bl_idname == "EXPORT_SCENE_OT_foobar"
- def draw(self, context):
- layout = self.layout
- layout.use_property_split = True
- layout.use_property_decorate = False # No animation.
- sfile = context.space_data
- operator = sfile.active_operator
- layout.prop(operator, 'extension')
- classes = (ExportFoobar, FOOBAR_PT_export_main)
- def menu_func_export(self, context):
- self.layout.operator(ExportFoobar.bl_idname, text="Export foobar")
- def register():
- for cls in classes: bpy.utils.register_class(cls)
- bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
- def unregister():
- bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
- for cls in classes: bpy.utils.unregister_class(cls)
- if __name__ == "__main__":
- register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement