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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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!
Podcast: Download (Duration: 6:29 — 5.9MB)
Hi there, Do you by chance have this working for Blender ver 2.8+?
Hi Ed, yes it works great in Blender 2.81 – I’ve just tested it, no amendments are necessary.
LOL–thanks man, I must have messed up the script in every way possible. Good to hear it works, cause I really have love for the Blender.
This is cool, but how do you re-import the key to use on another project?
I’ve described this for an older version of Blender, but the principle still works: https://www.versluis.com/2017/08/how-to-import-an-obj-as-shape-key-in-blender/