FBX exporter with a material overwrite with python

I am using the bpy.ops.export_scene.fbx operator and it works perfectly, but I was wondering if I am able to use the material overwrite for the export?

• What do you mean by "material overwrite"? – Robert Gützkow Sep 21 '19 at 16:39
• in the properties panel under scene/overwrite/material overwrite – Nburgess Sep 21 '19 at 16:42
• I thought you meant an options for fbx export. No, that won't work it's for rendering in Blender only. – Robert Gützkow Sep 21 '19 at 16:46

So I made a work around. The key was saving the original material, assigning the overwrite material, then reapplying the original. You will need to change the settings for the fbx export click here for its structure.

 fbxs = [ ob for ob in bpy.context.selected_objects]
bpy.ops.object.select_all(action='DESELECT')

for ob in fbxs:
ob.select_set(True)
mat = bpy.data.materials['Overwrite']
original_mat = ob.data.materials
ob.data.materials[0] = mat

bpy.ops.export_scene.fbx(...)

ob.data.materials[0] = original_mat
bpy.ops.object.select_all(action='DESELECT')