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?

  • $\begingroup$ What file format? $\endgroup$ – emackey Sep 14 '16 at 15:54
  • $\begingroup$ fbx file format $\endgroup$ – user22013 Sep 14 '16 at 16:28

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:
        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.

  • 4
    $\begingroup$ 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
  • $\begingroup$ Can you help me please? The script does basically nothing for me. At first I had a syntax error somehow, but a friend figured it out. Now no syntax error, but no .fbx files neither. Here is the current script: import bpy def export_all_fbx(): objects = bpy.data.objects for object in objects: bpy.ops.object.select_all(action='DESELECT') object.select_set(state=True) exportName = 'D:\\Exported\\' + object.name + '.fbx' bpy.ops.export_scene.fbx(filepath=exportName, use_selection=True) $\endgroup$ – 505Legion Mar 14 '20 at 16:04

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.

  • $\begingroup$ If you're not familiar with scripting in Blender, there are some good tutorials out there. It shouldn't be too complicated. $\endgroup$ – Matt Sep 14 '16 at 16:04
  • $\begingroup$ Does this script exist somewhere in the internet? I don't think there isn't, because making model for games is common. $\endgroup$ – user22013 Sep 14 '16 at 16:28
  • $\begingroup$ I'm sure someone has written one, but it's such a small thing that either it's too small to be worth publishing on the internet, or they've built it up to the point that they can sell it somewhere else. Yes, it's common to make models for games, but it's not common that you need to export objects from the same scene into different files. Typically, you'd have each object in its own scene. $\endgroup$ – Matt Sep 15 '16 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.