a bit late but anyway :)
import c4d
from c4d import gui
#Welcome to the world of Python
def main():
doc.StartUndo() # this generates an UNDO stack, every "AddUndo" between .StartUndo() and .EndUndo() will be "undoable" in a single "Ctrl+Z"
objects = doc.GetActiveObjects(0) # this get's currently active objects in a list. The "0" parameter means that we don't want to select the children of the objects and we don't care about the oreder of the returned selection
for obj in objects: # this iterates over the list of active objects. So for each object:
instance = c4d.BaseObject(c4d.Oinstance) # create a new instance object
instance.SetName(obj.GetName() + '_instance') # set it's name to the object's name + "_instance"
instance[c4d.INSTANCEOBJECT_LINK] = obj # set the instance's source object
instance.InsertBefore(obj) # insert the instance object in the object manager, right before the source object. You can use other options. Like .InsertAfter(obj), if you want it after the source object.
doc.AddUndo(c4d.UNDOTYPE_NEW, instance) # this adds the insertion of our new instance to the undo stack.
doc.EndUndo() # this ends the undo stack
c4d.EventAdd() # we infrom C4D that something has occured, otherwise it will not refresh until you click something or do something else
if __name__=='__main__':
main()