Need to convert/replace 100s of SpeedTree Materials with MaterialInstances

We have 100s of SpeedTree assets that we are importing into our project and the import process automatically creates Materials for each one. However we need to replace these Materials with MaterialInstances that all share the same handful of 3-4 parent Materials. We have not found any alternatives to doing this manually but it takes a relatively large amount of time and is tedious and error-prone. We were hopeful that the new editor scripting capabilities would let us do this but we’re hitting some roadblocks there.

Ideally we would like to write a script which does the following:

  • Given a selected material in the content browser:
  • Select a suitable parent material (based on a suffix in the name of the selected material)
  • Create a Material Instance using the suitable parent material
  • Discover the textures used by the original material
  • Plug each texture into the new material instance
  • Replace references to the original material with references to the new Material Instance
  • Delete the selected material

We’ve tried to do this in python and have run into missing functionality. For example in python we cannot set the parent material of a material instance and we can’t find a way to list the textures used by a material.

Are these things possible in the current python scripting system? Is there another way to approach this problem which we may have missed? (it seems like it would be a very common need).

Thanks for any help!
Greg