Skip to content

Instantly share code, notes, and snippets.

@kimmobrunfeldt
Created February 21, 2020 10:41
Show Gist options
  • Save kimmobrunfeldt/50715b8deff8534268fbb1e924038ac9 to your computer and use it in GitHub Desktop.
Save kimmobrunfeldt/50715b8deff8534268fbb1e924038ac9 to your computer and use it in GitHub Desktop.
Replaces a texture png with given command line input
# Run as: blender -b <filename> -P <this_script> -- <image_path>
# Example: blender -b myfile.blend -P render.py -- new_texture.png
import bpy, sys, os
# Assume the last argument is image path
imagePath = bpy.path.abspath(os.path.join(os.getcwd(), sys.argv[-1]))
if not os.path.exists(imagePath):
print("Image not found:", imagePath)
sys.exit(2)
# Change the image data block name to match your blender file
bpy.data.images['foil.png'].filepath = imagePath
# Render to separate file, identified by texture file
imageBaseName = bpy.path.basename(imagePath)
bpy.context.scene.render.filepath = os.path.join(os.getcwd(), 'render-' + imageBaseName)
# Render still image, automatically write to output path
bpy.ops.render.render(write_still=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment