Export .obj file with the name of the active object preselected

When you select export .obj from the File menu the name of the file will typically be preselected as the name of your Blender file but with the .obj extension or just object.obj if you haven't named your Blender file yet.

That's fine, you can change the name of course, but when I am working on a collection of object variants, I typically want to export them one a time and to be able to recognize them easily, I typically name the file after the name of the object.

Can this be simplified?

The Export Active Obj add-on

Yes, this can be simplified because we can add the export obj operator to the File menu again, but with the filename prefilled with the name of the active object.

The code is shown below, and it sets some common options I use all the time as well, but the essence is in line 7 (there is some more code in the add-on to set things up). 


def menu_func(self, context):
    self.layout.separator()
    op = self.layout.operator(
        "wm.obj_export",
        text="Export Active Obj",
    )
    op.filepath = context.active_object.name + ".obj"
    op.forward_axis = "Y"
    op.up_axis = "Z"
    op.export_selected_objects = True


def register():
    bpy.types.TOPBAR_MT_file_export.append(menu_func)

The code can be downloaded from my GitHub repo [file: export_active_obj.py] or directly from this link.


Tiny add-on to match data-block names to object names

I often find myself starting with a simple cube mesh, changing it a lot and then only after a while I give the object a meaningful name. I am pretty structured about this so even if my file ends up with a lot of objects, all objects will generally have a descriptive name.

However, the data blocks will at some point have names like Cube, Cube.001, Cube.002, etc., or even worse, have names that reflect other variants. Not a big deal  per se, but it might get confusing after a while so I'd like to rename all data blocks to match the name of the object.

The Name Match add-on

Renaming tens or even hundreds of objects can get tedious so I created a small add-on that when installed adds an item to the Object menu in the 3d-View.

The code is really simple indeed (see below, line 14 , the complete add-on has some extra code to create the menu entry): it assigns the name of the data-block for each selected object to the name property of the object itself. No need to check for objects with the same name because Blender will already take care of that.

When a data-block is linked to more than one object, the objects get names with numerical suffixes.

class NameMatchOperator(bpy.types.Operator):
    """Rename datablocks to match the name of the objects they are linked to"""

    bl_idname = "object.name_match"
    bl_label = "Name match"
    bl_options = {"REGISTER", "UNDO"}

    @classmethod
    def poll(cls, context):
        return len(context.selected_objects)

    def execute(self, context):
        for obj in context.selected_objects:
            obj.data.name = obj.name
        return {"FINISHED"}

Code availability

You can download it from my GitHub repo, or click this link to go to the code directly.