use mix-in classes for import export operators, these define the filepath property and invoke function at the moment.

This commit is contained in:
2010-09-01 02:25:49 +00:00
parent d67eedcef9
commit 5036a9d20c
12 changed files with 138 additions and 142 deletions

View File

@@ -854,19 +854,20 @@ Currently the exporter lacks these features:
'''
from bpy.props import *
from io_utils import ExportHelper
class ExportOBJ(bpy.types.Operator):
class ExportOBJ(bpy.types.Operator, ExportHelper):
'''Save a Wavefront OBJ File'''
bl_idname = "export.obj"
bl_label = 'Export OBJ'
filename_ext = ".obj"
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
filepath = StringProperty(name="File Path", description="Filepath used for exporting the OBJ file", maxlen= 1024, default= "", subtype='FILE_PATH')
check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'})
# context group
use_selection = BoolProperty(name="Selection Only", description="Export selected objects only", default= False)
use_all_scenes = BoolProperty(name="All Scenes", description="", default= False)
@@ -897,7 +898,7 @@ class ExportOBJ(bpy.types.Operator):
def execute(self, context):
filepath = self.properties.filepath
filepath = bpy.path.ensure_ext(filepath, ".obj")
filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
write(filepath, context,
EXPORT_TRI=self.properties.use_triangles,
@@ -921,14 +922,6 @@ class ExportOBJ(bpy.types.Operator):
return {'FINISHED'}
def invoke(self, context, event):
import os
if not self.properties.is_property_set("filepath"):
self.properties.filepath = os.path.splitext(bpy.data.filepath)[0] + ".obj"
context.manager.add_fileselect(self)
return {'RUNNING_MODAL'}
def menu_func(self, context):
self.layout.operator(ExportOBJ.bl_idname, text="Wavefront (.obj)")