& Construction

Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
& Manufacturing

Professional CAD/CAM tools built on Inventor and AutoCAD
Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
Professional CAD/CAM tools built on Inventor and AutoCAD
When exporting the FBX file it exports multiple meshes instead of exporting the selected duplicate. Here is the code.
import maya.cmds as cmds
# Get the currently selected object
selected_objects = cmds.ls(selection=True)
# Check if there is exactly one object selected
if len(selected_objects) != 1:
print("Please select exactly one object")
else:
# Get the selected object
selected_object = selected_objects[0]
# Check if the selected object is a mesh
if cmds.objectType(selected_object) != "mesh":
print("Please select a mesh")
else:
# Select the mesh
cmds.select(selected_object)
# Duplicate the object
duplicated_object = cmds.duplicate(selected_object, name="duplicated_object")[0]
# Export the duplicated object as an FBX file
export_path = "C:/Users/Devin/Desktop/"
cmds.select(duplicated_object)
FileName = (duplicated_object)
for i in FileName:
#extension = ".FBX"
mainpath = export_path+ "/" +i+extension
cmds.file(mainpath, force=True, options="v=0;", typ="FBX export", pr=True, ea=True)
Solved! Go to Solution.
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
# Get the currently selected object
selected_objects = cmds.ls(selection=True)
# Check if there is exactly one object selected
if len(selected_objects) != 1:
cmds.error("Please select exactly one object")
else:
# Get the selected object
selected_object = selected_objects[0]
# Check if the selected object is a mesh
if cmds.objectType(cmds.listRelatives(selected_object,c= True)[0]) != "mesh":
cmds.error("Please select a mesh")
else:
# Select the mesh
cmds.select(selected_object)
# Duplicate the object
duplicated_object = cmds.duplicate(selected_object, name="duplicated_{0}".format(selected_object))[0]
# Export the duplicated object as an FBX file
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!
@Kahylan Thank you I'm still new to coding as you can tell! But adding checks in is some good advice thank you for that. Is there any reading that you would recommend to help reinforce that method?
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Type a product name