How to export all Shape Keys as OBJ files in Blender

- by

To export a single Shape Key as OBJ file, all we have to do is set the desired Shape Key to 1 (or whatever value we like) and use the File – Export dialogue to create an OBJ with the shape/morph applied.

However, if you have several dozen Shape Keys that need to be exported, repeating the above several dozen times can be tedious and error prone. Blender hasn’t got an built-in option for such a batch-export operation, but thanks to a lovely man named TLousky, we can use a handy Python Script to do the job.

Here it is, with minor amendments by yours truly:


# Export all Shape Keys as OBJs in Blender
# Version 1.0 – August 2017
# =========================================
# Original Script by Tlousky
# https://blender.stackexchange.com/questions/86674/how-to-batch-export-shapekeys-as-obj-from-the-active-object/86678#86678
# with small tweaks by Jay Versluis
# https://www.versluis.com
import bpy
from os.path import join
# Reference the active object
o = bpy.context.active_object
# CHANGE THIS to the folder you want to save your OBJ files in
# NOTE: no spaces, no trailing slash
exportPath = "/Users/you/somewhere"
# Reset all shape keys to 0 (skipping the Basis shape on index 0
for skblock in o.data.shape_keys.key_blocks[1:]:
skblock.value = 0
# Iterate over shape key blocks and save each as an OBJ file
for skblock in o.data.shape_keys.key_blocks[1:]:
skblock.value = 1.0 # Set shape key value to max
# Set OBJ file path and Export OBJ
objFileName = skblock.name + ".obj" # File name = shapekey name
objPath = join( exportPath, objFileName )
bpy.ops.export_scene.obj( filepath = objPath, use_selection = True, global_scale = 1 )
skblock.value = 0 # Reset shape key value to 0
# THE END

Excellent… what exactly does it do?

This script will iterate over each Shape Key of the currently selected object, set each shape key to a value of 1, and export it to the desired path as OBJ file. Feel free to change the scale upon export if you like, and don’t forget to set a valid path for where you’d like your OBJs to be saved.

Awesome… how do we run this thing, Cap’m?

To run a script in Blender, open a Text Editor window (NOT the Python Console). I like using the Timeline Window for that. Click the New button to create a new text file. Now copy the entire code from above into the otherwise empty window inside Blender and hit the Run Script button at the bottom of the window.

Blender will go to work and do its thing. With a bit of luck, no error message will be displayed. Your destination folder should now contain the desired OBJ files.

I’ve explained how to do it all step-by-step in the above video.

Enjoy!



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

5 thoughts on “How to export all Shape Keys as OBJ files in Blender”

Leave a Comment