# Removing constraints & adding objects to group by python

I have a very basic script which I hope to do a couple things at once, but I am stuck at removing the constraint, and the group_link fails.

bpy.ops.constraint.delete()

and

What am I doing wrong? Note: the group does exist, it even has 1 object in it just to be sure. :)

EDIT:

Everything here works, now only to solve the constraint removal. :( :)

import bpy

for obj in bpy.context.selected_objects:

### get last 3 digits from object name and save them as objNumber
objNumber = obj.name[-3:]

### set object as Active
bpy.context.scene.objects.active = bpy.data.objects['Cube.'+objNumber]

### add Boolean and set the target to Cube
obj.modifiers["Boolean"].object = bpy.data.objects["Cube"]

### remove current constraints and add Copy Transforms, with target set to an Empty with the same number as original object
bpy.ops.object.constraint_delete()

• bpy.ops generally works on the active context object, which is only one of context.selected_objects generally index 0, always context.active_object. You can set the context object in a script with context.scene.objects.active = obj and use the operators. However you can add a constraint via con = obj.contstraints.new(name, type='COPY_TRANSFORMS') and then set its properties with con.target = empty. Will put together as an answer if required. – batFINGER Oct 7 '16 at 11:30