Linking Armature to object with python

Hey there,
first of all, happy new year^^

I’m trying to setup a full human model with an armature and link them together, all made automatically by python.

So now i am already at the point that my human model and my armature are generated (no it is no real human model, it is a very simple mathmatical one). Anyway, now i’m stucking at the point that i don’t know how to link my armature within the script.

I know those two ways to add a modifier:

ob = bpy.context.object
ob.modifiers.new(name = 'ObArmature', type = 'ARMATURE')

or with bpy.ops:

bpy.ops.object.modifier_add(type = 'ARMATURE')

but then i’ve got an empty armature modifier without knowing how to add the name to this modifier, as all modifiers are saved as a template and i don’t get the data property for a special armature modifier. So anybody knows how to define the armature, which shall be used for the modifier?

Haha, found it out on myself (after days of searching, at least…)

It’s very simple to add an armature to an object:


ob = bpy.data.objects['MyObject']
armt = bpy.data.objects['MyArmature']

ob.modifiers.new(name = 'Skeleton', type = 'ARMATURE')
ob.modifiers['Skeleton'].object = armt

That’s all, this will link an armature to an object.