Adding a constraint to an object?

I have a simple question
How to add a constraint to an object, and add a target.

I made a script constraint but i have a lot of targets to add, so i want to create a script that’s adds all the selected objects as targets.
And i cant add a script to a script constraint.

Somebody knows if this can be done

Here is some example code:


ob = Blender.Object.GetSelected()[0]
pose = ob.getPose()
bone = pose.bones['Bone.001']
          
constr = bone.constraints.append( Constraint.Type.PYTHON )
constr[Blender.Constraint.Settings.SCRIPT] = Text.Get('rule.py')
constr[Blender.Constraint.Settings.TARGET] = Blender.Object.Get('cube').name

Check out the possible Constraint.Settings options in detail here:
http://www.blender.org/documentation/249PythonDoc/toc-Constraint-module.html

I think if you have multiple targets, just pass a list to the TARGET attribute. “rule.py” would be your pyconstraint code in the text editor. I hope that helps.

Cheers,
Ivo

Loolarge thanks!
I will try that and see what happens
post the the result later

works perfect

 
 
import Blender as b 
ob = b.Object.GetSelected()[0]
pose = ob.getPose()
bone = pose.bones['Bone.001']
 
constr = bone.constraints.append( b.Constraint.Type.PYTHON )
constr[b.Constraint.Settings.SCRIPT] = b.Text.Get('replacer')
constr[b.Constraint.Settings.TARGET] =[b.Object.Get('Cube') ,b.Object.Get('Cube.001')]