I am trying to build a tool for calculating the IK pole angle of a constraint, I already posted a question here, but no answers. So I decided to go for brute force. Running a for loop and trying angles between -180 and 180 and seeing the difference with the rest position of the bone.
But the script does't works i returns too many angles supposed to be the right one when the truth is that only have one exact angle.
Here is the evaluating function, the full operator is a bit longer, so I put on PasteAll
# context is the bpy.context, # p_bone is the pose bone with the constraint # ik is the Inverse kinimatics constraint on the p_bone # angle is the angle to try and score def ik_test(context, p_bone, ik, angle): # mute constraint for getting original vectors of the bone ik.mute = True # then update the scene context.scene.frame_set(context.scene.frame_current) # get some vecotrs v1 = p_bone.vector x1 = p_bone.x_axis z1 = p_bone.z_axis # unmute the constraint ik.mute = False # set the pole_angle for the test ik.pole_angle = angle # update the scene again context.scene.frame_set(context.scene.frame_current) # get the new vectors v2 = p_bone.vector x2 = p_bone.x_axis z2 = p_bone.z_axis # lets see the diferences.. v_point = (v1 - v2).magnitude x_point = (x1 - x2).magnitude z_point = (z1 - z2).magnitude # lets get the total score total = v_point + x_point + z_point # with better score total sould be smaller, # but it returns zero at multiple angles # this only can happen if the scene does't update. print(angle, total) return (angle, total)