adding objects to an group

I cannot seem to find how to add objects to a group.

I have found this code example:

   # Make a new group with the selected objects, and add an instance of this group.
   from Blender import *
   
   scn= Scene.GetCurrent()
   
   # New Group
   grp= Group.New('mygroup')
   grp.objects= scn.objects

Does the line
grp.objects= scn.objects
add? the objects to the group? Could I use this to add single objects in sequence?

I am using this API link http://www.zoo-logique.org/3D.Blender/scripts_python/API/
Is there something else that could help me?

thanks in advance, c

You can use group.objects.link() and .unlink() for individual objects or for groups as in:



[grp.objects.link(o) for o in scn.objects]


Or to block assign (not sure what it does in terms of preserving already added objects, i.e. whether it removes them from the group or not), you can use your line. If your really interested in the behavior, you might try testing it out and seeing which gives you the proper behavior.