Exporting to FBX per OBJ name, but removing duplicate indicator and saving if not present

I appreciate any help on this. It seems a but more complicated than I have been able to return with a google.

I am attempting to export each object in a scene to FBX with loc and rot zeroed out. I have find a nice script posted at FBX Batch Export in Blender 2.8 - #2 by the_motionblur. So, this works. However, I would love to make this better by not saving the duplicate objects.

I would like to remove the “.xxx” if it exist in the object name. And then check to see if that file already exists in the folder, and if so then skip over it.

This doesn’t seem to removing the extra characters the denotes a duplicate object.


name =  ob.name
name = name.replace(".*", "")

but this does appear to be working to not create another saved fbx

if os.path.isfile(filename):
 print("Already Exist")

else:
bpy.ops.export_scene.fbx(filepath=filename, use_selection=True)

Are there any simple ways to do this?

Thanks!!

This worked. Please see the above link for the orginal author. I just changed a few things for my needs.

import bpy
import os
import re

#example path to store files
path = ‘E:\SteamLibrary\steamapps\common\App Game Kit 2\test1\media\levels\’

#store selection
obs = bpy.context.selected_objects

for ob in obs:
#deselect all but just one object and make it active
bpy.ops.object.select_all(action=‘DESELECT’)
ob.select_set(state=True)
bpy.context.view_layer.objects.active = ob

#store object location then zero it out
location = ob.location.copy()
bpy.ops.object.location_clear()
name = ob.name
name = re.sub("[.].*?$", '', name)
rotx = ob.rotation_euler[0]
roty = ob.rotation_euler[1]
rotz = ob.rotation_euler[2]
ob.rotation_euler[0] = 0
ob.rotation_euler[1] = 0
ob.rotation_euler[2] = 0

#export fbx
filename = path + name + '.fbx'
if os.path.isfile(filename):
    print("Already Exist")
else:
    bpy.ops.export_scene.fbx(filepath=filename, use_selection=True)

#restore location
ob.location = location
ob.rotation_euler[0] = rotx 
ob.rotation_euler[1] = roty
ob.rotation_euler[2] = rotz

#reselect originally selected objects
for ob in obs:
ob.select_set(state=True)