Modify modelImporter values and importing FBX via script

Importing custom character models from Mixamo, I’ve found that the default Rig Animation Type is Generic, so I have created a script to change their modelImporter to ensure that the Rig Animation Type is set to Humanoid. That enum is easy to set, but after I SaveAndReimport the modelImporter the avatar configuration is invalid. (None of the bones are matched as they are when you click “Apply” when setting the enum in the editor.) Is there a script method for forcing the auto-generation of the avatar?

Did you find a solution to this? I have the same issue.