I have a scene containing parts of a modular tileset to be used in the game. I want to export every object into separate files, and in every file object is moved to default (0, 0, 0) position.
How can I do this?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityI have a scene containing parts of a modular tileset to be used in the game. I want to export every object into separate files, and in every file object is moved to default (0, 0, 0) position.
How can I do this?
Here's a snippet of code that exports FBX. I tested it briefly and it appears to work. It just iterates the list of all objects, selects each one individually, and calls the FBX exporter on the selected object.
import bpy
def export_all_fbx(exportFolder):
objects = bpy.data.objects
for object in objects:
bpy.ops.object.select_all(action='DESELECT')
object.select_set(state=True)
exportName = exportFolder + object.name + '.fbx'
bpy.ops.export_scene.fbx(filepath=exportName, use_selection=True)
Example usage, shown here with a Windows-style path. Note that a trailing slash of some kind must be included due to use of simple concatenation of path and filename. Also note that backslashes must be escaped (doubled) but forward-slashes do not. Give it the name of an existing, empty folder with the trailing slash included.
export_all_fbx('C:\\outputFolder\\')
object.select = True
-------- This line of code is not supported in Blender 2.80 any more, use object.select_set(state=True)
instead. The rest of the code still works great.
$\endgroup$
– John Binary
Aug 18 '19 at 13:23
The best option would be to write a quick Python script.
Essentially, you'd use a for ... in
loop to iterate over all the objects. In that loop, you'd call whatever exporter you're using to export each object. You'll have to do some research to find out how to call it from Python, but it should be pretty simple.
It would also be a good idea to add some checks within that loop to skip certain objects (like the camera, or any empties).
Without actually sitting down and writing it, I can't be sure, but I'd be surprised (shocked, even) if the whole script was more than 10 lines.