I’m trying to put together a simple script to bake several images externally. Unfortunately, blender seems to ignore save_mode parameter and tries to bake internally no matter what I do. Anyone know if there is a way to make this work?
Your material needs a texture (image file node). It does not have to be properly linked, a loose node is enough.
I have made the experience that blender will always bake to the active texture image, cycles or in bi.
Just create a blank image and temporarily set it up as part of the material so it will bake onto it.
That said, I have no idea why the params don’t work as you intend them to, assuming the UI uses different ones (idk what they are actually for, nonetheless your full code might help find errors if they exist on your end). If this is indeed a bug, you’re better off with the workaround (for now). Regarding a bugfix, a full code sample as part of the report would speed things up as well.
Hmm, I wanted to bake to an external image without having to set up a material and select a texture node. The error message implies that this is possible, but maybe not anymore.
FWIW the full script is:
import bpy
import os
# export to blend file location
basedir = os.path.dirname(bpy.data.filepath)
if not basedir:
raise Exception("Blend file is not saved")
scene = bpy.context.scene
# fix selection
obj_active = scene.objects.active
selection = bpy.context.selected_objects
bpy.ops.object.select_all(action='DESELECT')
for obj in selection:
# setup selected to active bake
hiObj = bpy.data.objects["_HIPOLY_"+obj.name]
hiObj.select = True
obj.select = True
scene.objects.active = obj
fnDiffuse = os.path.join(basedir, "d.png")
fnNormal = os.path.join(basedir, "n.png")
bpy.ops.object.bake(type='DIFFUSE', pass_filter={'COLOR'}, filepath=fnDiffuse, width=1024, height=1024, margin=16, use_selected_to_active=True, save_mode='EXTERNAL', use_split_materials=False)
print("wrote:", fnDiffuse)
bpy.ops.object.bake(type='NORMAL', filepath=fnNormal, width=4096, height=4096, margin=16, use_selected_to_active=True, normal_space='TANGENT', save_mode='EXTERNAL')
print("wrote:", fnNormal)
obj.select = False
hiObj.select = False
# Restore selection
bpy.ops.object.select_all(action='DESELECT')
for obj in selection:
obj.select = True
scene.objects.active = obj_active
I Fraction ,
I know it’s a very old post and for now i’m working with blender 2.8 but i have the same problem.
after a long search i finish by find this post about a patch: https://developer.blender.org/D4162#change-rZP3yfLeSl8y
I think it’s a bug and we just wait the bugfix.
if evreybody have an solution before the devs fix this …