When working with blender, something you will most likely do is export your object. If there are a lot of these objects, and you want to export your meshes into seperate .obj files, it can be a very tedious job. The script below is one I use to make this as fast and easy as possible:
First, we loop over all the objects in the scene
(1) and check if the object is a mesh
If we found a mesh, we deselect everything in the scene
(3), and select the mesh we want to export
Then we define where the objects will be saved
(5). In this example the objects will be saved in a folder named
exports (optionally add the folder).
bpy.path.abspath will return the absolute path and the
// is an identifier in blender that points to the current blend file.
We add the data name of the object to it, along with the
.obj extension. If the blend file is not saved, the absolute path will be empty.
Last but not least, we export the obj with the settings we want
(6). In this example, only the selection and no materials will be exported.