Can you pack UV's according to material ID?
If you turn on the UV-edit mesh sync in the UV editor then you can select uv islands by materials in the materials tab. So select one material then hit Ctrl-P in the UV editor and repeat it with all of the materials.