Here is a simple script that given a material assetID and your desired slot, it will loop through all of your selected assets and update the mesh instance material.
Indeed a handy thing to do since that batch action isn’t allowed when selecting more than one model assets.
assetModelSetMaterial(15412718, 0);
function assetModelSetMaterial(assetId, slot) {
const type = editor.call("selector:type");
if (type !== "asset") {
return false;
}
const items = editor.call("selector:items");
if (!items || items.length === 0) {
return false;
}
items.forEach((item, index) => {
item.set("data.mapping." + slot + ".material", assetId);
});
console.log("--- Finished execution ---");
}