If I understand correctly, the shading assignments made in the referenced file are probably being lost because of edits that were made in the parent file.
One shotgun approach to see if this is true is to remove all edits from the parent file:
In the parent file, unload the referenced fileOpen the reference editor, RMB on the reference > File > Clean Up ReferenceThis will remove all modifications that were made to the referenced file from the parent file. If, when you reload the reference, your shading connections are correct then you can be pretty sure the original problem was due to one or more of the parent file edits.
If removing all the parent edits is not an option (i.e. there are some modifications you want to keep) your best bet may be to selectively remove only those edits which are unnecessary:
In the parent file, unload the referenced fileOpen the reference eidtor, RMB on the reference > File > List Reference Edits...Select those edits you want to remove and click "Remove Selected Edits"If you can identify the offending edits you may be able to manually clean up the scene.
An automated solution would be tougher. Assuming the problem is due to edits in the parent file breaking your referenced file shading connections, you can either:
Remake the shading connections in the parent file - unfortunately you'll need to know which assignments to make before hand.Automatically remove all edits in the parent file which might be suspicious. Using the referenceEdit and referenceQuery commands you can get information about, and remove, reference edits. In this situation some suspicious edits might be:
- connectAttr edits from your objects' iog plugs
- connectAttr edits to your shadingGroups' dagSetMembers (dsm) plugs
- parent edits - adding/removing/reparenting an instanced object will cause its shading connections be reshuffled
Note: reference edits can only be removed when the reference is unloaded.