Lets say I have 5 objects selected. The script will correctly export 5 fbx files, place them at 0-0-0 world space, export an fbx with the object name, and return them to their original position.
The problem is that each export includes all selected objects instead of 1 at a time. Shouldn't my for loop only grab each selected object 1 at a time? How do I select 5 objects, export them so a single object is inside each fbx with the corresponding name?
def execute(self, context):
# Get the selected objects.
selected = bpy.context.selected_objects
for obj in selected:
# Store current object's name.
obj_name = obj.name
# Get the object's original position.
obj_loc_x = str(obj.location.x)
obj_loc_y = str(obj.location.y)
obj_loc_z = str(obj.location.z)
# Creates the path for the exported fbx.
obj_path = os.path.join(context.scene.worth_group_tools.dir_path,
obj_name + "." + "fbx")
# Sends object to zero vectors.
obj.location.x = 0.0
obj.location.y = 0.0
obj.location.z = 0.0
# Export object as fbx. Works, except all selected objects are
# exported into single fbx instead of one at a time from the list.
bpy.ops.export_scene.fbx(filepath=obj_path, use_selection=True)
# Prints each object in list. Works.
print(obj_name)
# Returns the object to its original position.
obj.location.x = float(obj_loc_x)
obj.location.y = float(obj_loc_y)
obj.location.z = float(obj_loc_z)
return {'FINISHED'}