I wrote a python script that modifies an existing blender armature that I have and some of these modifications include some commands that are only possible in Edit Mode. I know that depending on what is selected, some modes are not possible to switch to. In my case Pose, Edit and Object mode are the three available modes when I select my armature. In this instance, the following three commands could be used:
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.mode_set(mode='OBJECT')
Of the above three only the second one switches to wrong mode i.e. Object Mode. I found no similar questions/forums on this kind of issue. When trying to change to Edit Mode, blender changes to Object mode and my commands that are intended for edit mode show context error messages (as expected if in Pose/Object mode..) making it not possible for my script to apply the correct changes.
Does anyone have any idea why this is happening and how I could stop this from happening?? Thanks