selecting bones in armature's edit mode

Hi
I was writing an auto tasking script to create a Deform armature from a rig

I had an issue that i couldn’t find a proper way to select bones in edit mode
the only ways to do it was either to use the “select pattern” ops
bpy.ops.object.select_pattern(pattern = bone.name)
or to select it in pose mode and then to switch to edit mode.
couldn’t find also anything in the documentation except for the old API.

any ideas?

I was also wondering if there ways to remove objects or bones with the standard python functions for lists like list.pop() or .remove() or can i do it only with blender’s operators?

You need to be in editmode, then set the edit_bones’ select properties,

e.g. C.object.data.edit_bones[0].select = True
.select_head = True
.select_tail = True

Bones can be removed like

edit_bones.remove(edit_bones[#]),
looks like you don’t see the change until you click in the viewport however…

Objects like bpy.data.objects.remove(ob), but only if there are no users left (ob.data is a user). So it might be better to use bpy.ops.object.delete()

2 Likes

cool, thanks. it was a bit confusing between bones, edit_bones and different accesses to each one.
i was wondering if normally it would be better to use the functions in blender API rather then the blender ops?

Definitely yes:

Hey bro how can we determine the list index in the example above…
THANKS IN ADVANCE…