1

I want to, perhaps using the command line, run Blender in background mode and have it process a large number of individual .obj files. "Process" means applying a few commands to the single mesh contained within each .obj file, and then export each modified mesh as a new .obj file in a new dir. TLDR: I've made a script, but the problem I'm having is understanding how I would run the script upon a large number of .obj files.

Here's what I have so far.

import os
import bpy

bpy.ops.object.editmode_toggle()

bpy.ops.mesh.normals_make_consistent(inside=False)

bpy.ops.transform.resize(value=(100, 100, 100))

bpy.ops.export_scene.obj(filepath="C:\\output", check_existing=True)

This seems like a simple problem, but no amount of googling has helped. Documentations says I can execute the following in cmd, but I don't understand how I would translate it to this situation.

blender myscene.blend --background --python myscript.py

Remember, I'm working with a ton of .obj files, no .blend files.

  • You want to use a loop that will perform the same thing for each file. [This answer](https://stackoverflow.com/a/41939643/2684771) is an example of importing and exporting multiple objs - add your steps into the loop. – sambler Oct 19 '18 at 03:45

1 Answers1

2

You can do this in the command line using say a for loop in Windows cmd.exe

for %%F IN (file1.blend,flie2.blend,file3.blend) DO (blender %%F --background --python myscript.py)

Or under unix (bash/sh)

for file in *.blend; do blender "$file" --background --python myscript.py; done

Or have I not understood your question. This answer seems to simple.

Kingsley
  • 14,398
  • 5
  • 31
  • 53
  • Using the first one, what could I replace the list of .blend files with? I have a large directory of .obj files, not a small list .blend files. How would blender know to import those from cmd? Wrap the commands in an import script? –  Oct 19 '18 at 04:10