Assigning dif. materials to objects through transformations

I have a script in which assemblies of components that need to be assigned different materials are subject to the same transformations (moving).

I have not figured out an efficient way to do this. Right now I have to group them by material then ungroup them after the transformations have been applied. Is there a better way to achieve this?

Thank you,

Ian