text: # exports each selected object into its own file
  import bpy
  import os
  
  # export to blend file location
  basedir = os.path.dirname(bpy.data.filepath)
  
  if not basedir:
      raise Exception("Blend file is not saved")
  
  selection = bpy.context.selected_objects
  bpy.ops.object.select_all(action='DESELECT')
  
  for obj in selection:
      obj.select = True
      name = bpy.path.clean_name(obj.name)
      fn = os.path.join(basedir, name)
      bpy.ops.export_scene.obj(filepath=fn + ".obj", use_selection=True, axis_forward='Y', axis_up='Z')
      ## Can be used for multiple formats
      # bpy.ops.export_scene.x3d(filepath=fn + ".x3d", use_selection=True)
      obj.select = False
      print("written:", fn)
  
  for obj in selection:
      obj.select = True
  