Changing default animation type to Humanoid via script

Hello! I’m trying to change default animation type during .fbx import to Humanoid via Editor script using this little piece of code:

    public class ChangeModelToHumanoid : AssetPostprocessor
    {
        void OnPreprocessModel()
        {
            ModelImporter modelImporter = assetImporter as ModelImporter;
            modelImporter.animationType =   ModelImporterAnimationType.Human;
            EditorUtility.SetDirty(modelImporter);
            EditorApplication.SaveAssets();        
        }
    }

While it seems to change the setting properly, Unity is unable to automatically generate avatar for imported animations, displaying following warning:

Required human Bone Hips not found

Is there any proper way to change the dafault import option and still get a working avatar?

This is what I ended up using. Using existing avatar as a template.

-Resources have a pre-converted model with the avatar (named as template “Max”, “MakeHuman”, etc)

-Input folder is where models will be auto imported and converted to humanoid.

private string[] templates = new string[] {  "Max_", "MakeHuman_"};
    //based on name prefix or if in a folder (Input/Max_/anymodel.fbx) will also work. 
    //matches up it's avatar from one in the resources folder
   
    void OnPreprocessModel()
    {
        if (assetPath.Contains("Input"))
        {
            ModelImporter importer = (ModelImporter)assetImporter;

            //Load in the preconfigured avatar from the resources folder
            foreach (string template in templates)
            {
                if (assetPath.Contains(template))
                {
                    //Switch to humanoid
                    importer.animationType = ModelImporterAnimationType.Human;
                    //Trim off the underscore
                    string trim = template.Substring(0, template.Length - 1); 
                    //Apply the avatar from the resources folder
                    importer.sourceAvatar = Resources.Load<Animator>(trim).avatar;
                    break;
                }
            }
            //Log a warning if we didn't find a match 
            Debug.LogWarning("Model prefix does not correspond to any pre-configured humanoid avatar.");
        }
    }

    void OnPostprocessModel(GameObject model)
    {
        if (assetPath.Contains("Input"))
        {
            ModelImporter importer = (ModelImporter)assetImporter;
            
            //Add the animator and preconfigure it.
            if (!model.GetComponent<Animator>())
            {
                model.AddComponent<Animator>();
                model.GetComponent<Animator>().avatar = importer.sourceAvatar;
                model.GetComponent<Animator>().applyRootMotion = true;
            }
        }
    }