Batch export to OBJ from Blender

We can export any mesh from Blender to a file in OBJ format by selecting it and pressing the following items from the main menu: FIle – Export – Wavefront (.obj). If we need to split the scene into objects and export each of them to OBJ, this process can be easily automated.

Let’s write a small script that will allow us to simultaneously export all the meshes selected in the scene – each mesh into a separate file in OBJ format.

First, define the place where we will put the meshes exported from Blender. Let this be the same directory in which the .blend file with the current scene is located.

The export to OBJ operator in Blender works with all selected objects at once. Therefore, to break the scene object by object, we need to save the list of selected objects and deselect them all. And then, selecting each mesh by this list one by one, export it to OBJ format.

Create a copy of the selected objects list,

and deselect all of them.

Next, let’s loop through the previously saved list of objects:

If the object is a mesh, select it, execute the export to OBJ operator and deselect it again so that it is not exported again in the next iteration of the loop.

In the “filepath” parameter of the “obj_export()” operator, we pass the full path, including the extension, to save the mesh in OBJ format. In our example, this will be the path to the .blend file directory plus the file name and the “.obj” extension. As the file name, we use the name of the exported mesh, which we get from its “name” property.

After all, we can restore the original selection in the scene.

After executing this simple code, OBJ files will be created in the project directory, each of which will contain a separate exported mesh from the Blender scene.

0 0 votes
Article Rating
Notify of

0 Comment
Inline Feedbacks
View all comments