Creating Context Menu Item for FBX files

I would like to add a context menu option for imported .FBX files. I previously had the same functionality in the AssetImporter, but I don’t want this functionality to happen for all .FBXs imported. I don’t want it to be automatic.

The specific functionality is just that I want to set the .FBX’s animation clips’ masks to ‘create from this model’ and set the avatar mask to every child bone.

Here’s the method I used in the Asset Importer:

/// <summary>
/// Automatically set this model importer's mask type to 'CreateFromThisModel' and set the mask
/// to the entire hierarchy.
/// </summary>
public static bool CreateMaskFromThisModel(this ModelImporter modelImporter, GameObject model)
{
    bool changed = false;

    ModelImporterClipAnimation[] clips = modelImporter.clipAnimations;

    if (clips == null || clips.Length == 0)
        clips = modelImporter.defaultClipAnimations;

    ModelImporterClipAnimation[] newAnims = new ModelImporterClipAnimation[clips.Length];

    for (int i = 0; i < clips.Length; i++)
    {
        if (clips*.maskType != ClipAnimationMaskType.CreateFromThisModel)*

{
newAnims = clips*;*
newAnims*.maskType = ClipAnimationMaskType.CreateFromThisModel;*

changed = true;
}
}

AvatarMask mask = new AvatarMask();
mask.AddTransformPath(model.transform, true);

for (int i = 0; i < clips.Length; i++)
{
if (clips_.maskSource == null || clips*.maskSource.transformCount != mask.transformCount)
{_

_clips.ConfigureClipFromMask(mask);
changed = true;
}
}*_

modelImporter.clipAnimations = clips;

return changed;
}
----------
This works. However, I seem to have no way to access the model importer after the import, at will. This is as far as I’ve gotten for my context menu.
[MenuItem(“Assets/Create Mask From This Model”, isValidateFunction: true)]
private static bool CheckIfFBX()
{
if (Selection.gameObjects.Length == 0)
return false;

for (int i = 0; i < Selection.gameObjects.Length; i++)
if (!AssetDatabase.GetAssetPath(Selection.gameObjects*).ToLowerInvariant().EndsWith(“.fbx”))*
return false;

return true;
}

[MenuItem(“Assets/Create Mask From This Model”)]
private static void CreateMaskFromThisModel()
{
for (int i = 0; i < Selection.gameObjects.Length; i++)
{
// get importer, clips, avatar mask, anything?
}
}

(I know the answer is late, but for anyone with similar problems it’s still relevant)

There is no way to selectively import directly.
However, what you can do is create a scriptable object that keeps a queue of FBX files.

So essentially on CreateMaskFFromThisModel(), you load the ScriptableObject via AssetDatabase, then you add the asset path of the fbx to the list in the ScriptableObject.

After that you need to trigger a reimport via script on this asset directly after.

Now, your AssetImporter, which is called on every imported object loads the same ScriptableObject (make sure to keep it around as a static reference to not do a load on every import). It then checks if the asset path of the imported object matches the any of the paths in the queue. If it does, you trigger whatever you want to in the asset importer and then remove the entry from the ScriptableObject.