Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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