I've done this a few times when the rim has worn out due to long-term wear of the braking surface. Pretty easy to temporarily tape the new rim to the old one and then move the spokes over one at a time. That way all the orientations are automatically preserved and the spokes remain in any shallow grooves they may have created in the hub flanges.