How to copy a UV map to multiple duplicated objects at once with Python script in Maya

When modeling objects, we duplicate an object multiple times and realize

‘Oh, I forgot to unwrap the UV!'

You can copy a UV map to another object via [Mesh > Trasnfer Attributes] tool.
However, this tool only allows copying an attribute from one to another. One to multiple objects is impossible, at least not yet.

Such a repetitive work can be done through scripts.

Select an object that contains the UV map you want to copy, and select the rest of the objects whose UV maps you want to be pasted.
Then run the following script.

import maya.cmds as cm
from maya.OpenMaya import MGlobal

selectedObjects = cm.ls(selection=True)
original = selectedObjects.pop(0)

for target in selectedObjects:
    cm.select([original,target])
    cm.transferAttributes(sampleSpace=4,transferUVs=2)
else:
    MGlobal.displayInfo("UV copy finished")

One thing to notice is that this script can be used to copy a UV map and paste to duplicated objects. That is, objects should contain same number of vertices, faces, and edges, and the relationship between these componenets must be the same on all selected objects.