# How do I run a script on multiple .blend files from the command line?

Problem: I have a bunch of .blend files that I want to make the same changes to as quickly as possible.

Solution: Run a python script on each file from the command line?

Here's the python script I'm currently using:

import bpy

#show all layers
bpy.context.scene.layers = ((True,)*20)

#delete the camera, sun and ground
for obj in bpy.data.objects:
obj.select = False
if obj.name == "sun":
obj.select = True
elif obj.name == "ground":
obj.select = True
elif obj.name == "camera":
obj.select = True
bpy.ops.object.delete(use_global = False)

for ob in bpy.data.objects:
ob.location[0] = ob.location[0] / 10
ob.location[1] = ob.location[1] / 10
ob.location[2] = ob.location[2] / 10

#save the file and quit
bpy.ops.wm.save_mainfile()


And here's the .bat file:

cd C:\Program Files\Blender Foundation\Blender



The python script works inside Blender, but when I run the .bat file (in admin mode) it just closes. What am I doing wrong?

Bonus: Is there a way to simplify the .bat script so that it just runs on every .blend file in the folder without them being typed out?

• You can check if there is any error by running it from direct commandline, I think, but I will try to run it from my computer also. – Alperen Üretmen Jun 17 '17 at 11:46
• By the way is script working in Blender when you try to run it manually? – Alperen Üretmen Jun 17 '17 at 11:54
• Originally, no it wasn't working (I was thinking of a different script when I posted this). I've corrected it now (and updated my post), so the script definitely runs in Blender from the text editor but the problem of running it from the command line persists. – BlenderBro Jun 17 '17 at 13:05
• Try using forward slashes in your path. Backslashes have different meanings in different environments, so are often a cause of trouble. You also don't need to specify the full path, relative paths are fine too. – dr. Sybren Jun 17 '17 at 14:08
• No change when using forward slashes. – BlenderBro Jun 17 '17 at 15:23