Can someone explain the use of “object.mode_set()” when using Blender without the GUI? The poll() for this function seems to require the GUI to be loaded, but I don’t understand why this would be the case.
I am using Blender 2.54.
The following script creates a monkey, and then triangulates it.
import bpy # Add a monkey bpy.ops.mesh.primitive_monkey_add() # Triangulate bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='SELECT') bpy.ops.mesh.quads_convert_to_tris()
When I run the script from within blender, it works as expected.
When I run the script from the command line, but loading the GUI, it works as expected:
# Works correctly blender -P script.py
But when I run the script from the command line, without loading the GUI, it fails:
# Fails blender -b -P script.py
The return is: “Operator bpy.ops.object.mode_set.poll() failed, context is incorrect.”
Perhaps there’s a good reason for the mode_set() function to require the GUI to be loaded. But is there really no way to change the mode then?
Thanks so much.