def group_elements(drawing, anchors=None):
    """ Combine all elements in a drawing into a single element that can be added to
        another drawing. Returns an element definition.

        Parameters
        ----------
        drawing: Drawing
            The Drawing object. All elements in this drawing will be combined.
        anchors: dict (optional)
            New anchor dictionary to use for the new element.
    """
    elmdef = {'paths': [], 'pathparams': [], 'shapes': [], 'labels': [],
        'extend': False}
    for elm in drawing.elements:
        for segment in elm.segments:
            newdef = segment.getdef()
            elmdef['paths'].extend(newdef.get('paths', []))
            elmdef['pathparams'].extend(newdef.get('pathparams', []))
            elmdef['shapes'].extend(newdef.get('shapes', []))
            elmdef['labels'].extend(newdef.get('labels', []))
    if anchors is not None:
        elmdef['anchors'] = anchors
    elmdef['drop'] = drawing.here
    return elmdef
