Hi!
The reason your script exports multiple files is that you have the exportAll(ea) flag set to true in your file command instead of exportSelected(es)
Now there are quite a few other issues with your script. Your checking logic doesn't really stop the program, it just prints out statements but moves on like nothing happend if you have a wrong selection. Also your check for "mesh" if it would work, it would require the user to select the shape node instead of the transform. That would be quite confusing for most users.
Having a check function that makes sure you only have one object selected but then running the File creation from a loop also doesn't really make sense. Especially since you needed to redeclare your string as a tuple with a string in it to work.
The name of your duplicate object is always "duplicate_object" this will result in the file always being called "duplicate_object" which will cause file clashing issues. Adding the actual name of the object instead of "object" can fix this issue to some degree.
Also The variable "extention" gets called without being defined. but I guess that was a last minute try to fix things before you uploaded here.
So here is how I would fix that:
import maya.cmds as cmds
import maya.mel as mel
selected_objects = cmds.ls(selection=True)
if len(selected_objects) != 1:
cmds.error("Please select exactly one object")
else:
selected_object = selected_objects[0]
if cmds.objectType(cmds.listRelatives(selected_object,c= True)[0]) != "mesh":
cmds.error("Please select a mesh")
else:
cmds.select(selected_object)
duplicated_object = cmds.duplicate(selected_object, name="duplicated_{0}".format(selected_object))[0]
export_path = "users/itz/desktop"
cmds.select(duplicated_object, r= True)
mainpath = export_path + "/" + duplicated_object + ".fbx"
mel.eval( 'FBXExport -f "{0}" -s'.format(mainpath) )
Now cmds.file(typ= "FBX export") seems to be Maya version dependant. I never really could get it to work, so I used the FBX MEL wrap instead here so I could make sure it worked, but if it works for you, you can change the last line to:
cmds.file(mainpath, force=True, options="v=0;", typ="FBX export", pr=True, es=True)
I hope it helps!