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)

#adjust object locations
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

And here's the .bat file:

cd C:\Program Files\Blender Foundation\Blender

blender -b "C:\[path]\file_01.blend" --python "C:\[path]\adjust.py"
blender -b "C:\[path]\file_02.blend" --python "C:\[path]\adjust.py"

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?

  • $\begingroup$ 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. $\endgroup$ Jun 17, 2017 at 11:46
  • $\begingroup$ By the way is script working in Blender when you try to run it manually? $\endgroup$ Jun 17, 2017 at 11:54
  • $\begingroup$ 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. $\endgroup$
    – BlenderBro
    Jun 17, 2017 at 13:05
  • $\begingroup$ 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. $\endgroup$
    – dr. Sybren
    Jun 17, 2017 at 14:08
  • $\begingroup$ No change when using forward slashes. $\endgroup$
    – BlenderBro
    Jun 17, 2017 at 15:23

2 Answers 2


There is nothing wrong with either script. The problem was the use of an ampersand (&) in the file path. Don't use special characters in your folder/file names. Newbie mistake on my part.


I put up together an Autohotkey script that does exactly that (requires Windows and Autohotkey v1 installed) https://github.com/Flowgun/BlenderBatcher

  • $\begingroup$ While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review $\endgroup$ Feb 14 at 15:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .