I am only just starting to learn/use python in blender. I have the following script
import bpy for obj in bpy.data.objects: if obj.name[0:4] == "Text" and obj.type == "MESH": bpy.context.scene.objects.active = obj bpy.ops.object.mode_set(mode = 'EDIT') print(bpy.context.mode) #bpy.ops.mesh.select_all(action = 'SELECT') #print(bpy.ops.mesh.remove_doubles(0.0001)) bpy.ops.object.mode_set(mode = 'OBJECT')
I am trying to work out why I keep getting a context error for bpy.ops.mesh.select_all so I added the
print(bpy.context.mode) line and commented out the line that was failing (plus the next line which takes action)
what I get in the console (this script is being run from the console rather than run in place) is a mixture of 'OBJECT' and 'EDIT_MESH' outputs.. suggesting that mode_set is failing a lot of the time.
What am I doing wrong?
I am using blender 2.68a on Windows 7.
Edit I discovered the actual cause of my issue (hinted at by Adhi's edit) and wanted to add it to my post so that others can take something away from this - the objects that were not being switched into edit mode were on another layer. Once I made all layers active my script was able to switch all objects into edit mode. So basically an object in an unselected layer cannot be set into edit mode.
I am also grateful for the other help and suggestions, they have been useful to help me learn python scripting within blender which is something I would love to use more extensively.