0
$\begingroup$

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')
$\endgroup$

1 Answer 1

0
$\begingroup$

Generated answer cleared things up in this case -

The "exportshapes" function is defined to return a value of "None", so when you call it and assign its return value to the "execute" function's return value, you are attempting to return a "NoneType" object, which is not a valid return value for the "execute" function.

The "execute" function is expected to return a set of three possible string values:

'FINISHED'
'CANCELLED'
'INTERFACE'

These values indicate the status of the operator after it has completed its task. 'FINISHED' indicates that the operator completed successfully, 'CANCELLED' indicates that the operator was interrupted or cancelled before it could complete, and 'INTERFACE' indicates that the operator is requesting user input through the interface.

If you want to return 'FINISHED' after calling the "exportshapes" function, you can modify the "exportshapes" function to return 'FINISHED' instead of "None". Alternatively, you can modify the "execute" function to call the "exportshapes" function and then return 'FINISHED' afterwards, like this:

def execute(self, context): exportshapes(self.filepath) return {'FINISHED'}

This way, the "execute" function will always return 'FINISHED', regardless of the return value of the "exportshapes" function.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .