Don't feel sorry yes this is the issue and since Knot ID are not ordered from right to left but from creation order its why it's confused you.
Moreover, using a for loop will make way more sense and help you to avoid this kind of stuff.
grad1 = shdr1[c4d.SLA_GRADIENT_GRADIENT]
grad2 = shdr2[c4d.SLA_GRADIENT_GRADIENT]
for knotId in xrange(grad1.GetKnotCount()):
knot = grad1.GetKnot(knotId)
grad2.InsertKnot(col=knot['col'], pos=knot['pos'],index=knot['index'])
grad2.FlushKnots()
shdr2[c4d.SLA_GRADIENT_GRADIENT] = grad2
Finally, a BaseShader is derived from BaseList2D which is derived from C4DAtom that mean you can use GetClone to retrieves a clone of this shader so your code can look like.
import c4d
def main():
mat = doc.GetFirstMaterial()
colorShader = mat[c4d.MATERIAL_COLOR_SHADER]
if colorShader is None:
return
copyColor = colorShader.GetClone()
mat[c4d.MATERIAL_DIFFUSION_SHADER] = copyColor
mat.InsertShader(copyColor)
mat.Message(c4d.MSG_UPDATE)
mat.Update(True, True)
c4d.EventAdd()
# Execute main()
if __name__=='__main__':
main()
Cheers,
Maxime.