Acessing bone IK constraint in python

hello all…

this may seem rather basic, but I am hoping sombody can help me fastly answer this question:

How to access a bone constraint in python?

I know from research to access a regular constraint it is something like:

constraint = object.constraints[“Bone:ConstraintName”]

how to now do this so to access a bone specific constraint? IE A childOf constraint on your IK bone for a hand…

thanks all

Please someone can tell me how if this is possible?

There is so much more i can do if I know how to do this!

Have a look at bge.types.BL_ArmatureChannel. It has a lot of attributes related to Inverse Kinematics. I don’t think the Childof constraint is accessible in the BGE through Python. Maybe someone else can tell you for sure.

Edit: When searching http://www.blender.org/documentation/blender_python_api_2_71_release/search.html?q=ik&check_keywords=yes&area=default at the bottom there also are some handles related to the IK constraint. I’m not sure how to use these though.

surely there is a way somebody must know.

I can’t believe it only possible to change with animations.

you can set copy rot, to objects then manipulate the objects?

Attachments

Rotset12.blend (450 KB)

not the same ffect really…

I am looking to press P, and be abble to change the influence of a childOf constraint on my IK bone so it moves to the object…

Unfortunately drivers are no option in the BGE. Otherwise this would be what you’re looking for, I think.

I tried to do a similar thing just recently actually,

I found this code will work for the transforms constraints and I am pretty sure the tracking constraints:

sense = cont.sensors['Keyboard']

armature = own.scene.objects['Armature'] 
constraint = armature.constraints[0] 

if sense.positive:
     constraint.active = False

To access different constraints, just change the array position from 0 to whatever. 0 being the first slot of course.

An alternative method would be to use a loop and assign the desired constraints into variables by name using a loop through all of a bones constraints. This will also work for all transform and tracking constraints.

if cont.sensors[0].positive:
    bone = own.channels["top"]
    for i in own.constraints:
    if i.name == "transforms":
        storage = i
    

Which ever on you choose, you could then edit influence (enforce), target, active state, ect.

However, I could get neither of these codes to work for the relationships constraints sadly. Maybe I did something wrong for them. If somebody can see why they would not work with my code, feel free to fix it and use it.