Advertisement
Guest User

Untitled

a guest
Jan 7th, 2021
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. import bpy
  2. from bpy_extras.io_utils import ExportHelper
  3.  
  4.  
  5. class ExportFoobar(bpy.types.Operator, ExportHelper):
  6.     bl_idname = "export_scene.foobar"
  7.     bl_label = 'Export Foobar'
  8.     bl_options = {'PRESET'}
  9.  
  10.     filename_ext = ''
  11.     filter_glob: bpy.props.StringProperty(default='*.foo;*.bar', options={'HIDDEN'})
  12.  
  13.     extension: bpy.props.EnumProperty(
  14.         name='Extension',
  15.         items=(('FOO', '.foo', '.foo'), ('BAR', '.bar', '.bar')),
  16.         default='FOO',
  17.     )
  18.  
  19.     def execute(self, context):
  20.         print(self.filepath)
  21.         return {'FINISHED'}
  22.  
  23.     def check(self, context):
  24.         print('check called')
  25.  
  26.         import os
  27.         changed = False
  28.  
  29.         filepath = self.filepath
  30.         if os.path.basename(filepath):
  31.             filepath = bpy.path.ensure_ext(
  32.                 filepath,
  33.                 '.foo' if self.extension == 'FOO' else '.bar',
  34.             )
  35.             changed = (filepath != self.filepath)
  36.             self.filepath = filepath
  37.  
  38.         return changed
  39.  
  40.     def draw(self, context):
  41.         pass
  42.         # NOTE!: if the prop is drawn here instead of in a panel, check is
  43.         # called automatically without having to do anything special
  44.  
  45.  
  46. class FOOBAR_PT_export_main(bpy.types.Panel):
  47.     bl_space_type = 'FILE_BROWSER'
  48.     bl_region_type = 'TOOL_PROPS'
  49.     bl_label = ""
  50.     bl_parent_id = "FILE_PT_operator"
  51.     bl_options = {'HIDE_HEADER'}
  52.  
  53.     @classmethod
  54.     def poll(cls, context):
  55.         sfile = context.space_data
  56.         operator = sfile.active_operator
  57.  
  58.         return operator.bl_idname == "EXPORT_SCENE_OT_foobar"
  59.  
  60.     def draw(self, context):
  61.         layout = self.layout
  62.         layout.use_property_split = True
  63.         layout.use_property_decorate = False  # No animation.
  64.  
  65.         sfile = context.space_data
  66.         operator = sfile.active_operator
  67.  
  68.         layout.prop(operator, 'extension')
  69.  
  70.  
  71. classes = (ExportFoobar, FOOBAR_PT_export_main)
  72.  
  73.  
  74. def menu_func_export(self, context):
  75.     self.layout.operator(ExportFoobar.bl_idname, text="Export foobar")
  76.  
  77.  
  78. def register():
  79.     for cls in classes: bpy.utils.register_class(cls)
  80.     bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
  81.  
  82.  
  83. def unregister():
  84.     bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
  85.     for cls in classes: bpy.utils.unregister_class(cls)
  86.  
  87.  
  88. if __name__ == "__main__":
  89.     register()
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement