I need to export the shape keys of the active object to a folder specified by the user. I'm trying to modify the built in template for export operators, but struggling to find documentation on the subject.
The shape key export function works as expected, but can't figure out a way to return the filepath from the dialogue and use that to run my function from within the dialogue, if that makes sense. Basically, when running the script I would need the file dialog to pop up, user is choosing a folder, and the shape keys are getting exported into that folder.
import bpy
import os
def exportshapes(filepath):
obj = bpy.context.active_object
filepath = os.path.dirname(filepath)
for k in obj.data.shape_keys.key_blocks:
bpy.ops.wm.obj_export(
filepath=filepath,
export_selected_objects=True,
export_normals=False,
export_materials=False)
# ExportHelper is a helper class, defines filename and
# invoke() function which calls the file selector.
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator
class ExportSomeData(Operator, ExportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "export_test.some_data" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Export Shapes"
# ExportHelper mixin class uses this
filename_ext = ".obj"
def execute(self, context):
return exportshapes(self.filepath)
def register():
bpy.utils.register_class(ExportSomeData)
def unregister():
bpy.utils.unregister_class(ExportSomeData)
if __name__ == "__main__":
register()
# test call
bpy.ops.export_test.some_data('INVOKE_DEFAULT')