0
$\begingroup$

I am new to python and need to select the tail of a bone in edit mode with python. I was used this script but it doesn’t select the tail of a bone:

bpy.data.armatures["Armature"].bones["Bone.001"].select_tail=True

So i need help to select the tail of a bone in edit mode with python code.

Any helps are very very welcome.

$\endgroup$

1 Answer 1

0
$\begingroup$

I'm not sure why this is, but selecting stuff in edit mode only works using bpy.ops.select_all() or execute the code in object mode and the switch back to edit mode. where ob is my armature object:
ob.data.bones['Bone'].select_tail = True
works if you're in object mode and then press tab in the viewport.

import bpy
arm = bpy.data.armatures['Armature']
bpy.ops.object.mode_set(mode='OBJECT') # .select only has an effect in object mode (don't ask me why)
for bone in arm.bones: # deselect the other bones
    bone.select = False
    bone.select_tail = False
    bone.select_head = False

arm.bones['Bone'].select_tail = True
bpy.ops.object.mode_set(mode='EDIT') # go back to Edit Mode, to see the results
$\endgroup$
9
  • $\begingroup$ your script works one time perfectly and doesn't work again. I get eror Traceback (most recent call last): File "<blender_console>", line 1, in <module> NameError: name 'ob' is not defined This is your script i have used ob.data.bones['Bone'].select_tail = True any helps ? $\endgroup$
    – Kask909
    Commented Apr 2, 2020 at 17:33
  • $\begingroup$ Nobody to help ? $\endgroup$
    – Kask909
    Commented Apr 3, 2020 at 23:14
  • $\begingroup$ Sorry, I should have clarified. ob is your armature object. Use your code in object mode, then switch to edit. $\endgroup$ Commented Apr 5, 2020 at 14:54
  • $\begingroup$ @ Frederik Steinmetz can I have the full code iam new to python $\endgroup$
    – Kask909
    Commented Apr 6, 2020 at 20:29
  • $\begingroup$ I did so, couldn't do it before today, bc. I was not in front of a computer. $\endgroup$ Commented Apr 7, 2020 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .