How to: Creating macros in Blender

I just found out how easy it is to create macros in Blender. Here’s how:

The python script below sorts the elements of all selected objects by material. This makes geometry indexes in Urho3D correspond with the object’s list of materials in Blender. Without macros this would be quite tedious and time-consuming work if you need to do it for many objects.

Python script for sorting elements of all selected objects by material
import bpy
for ob in bpy.context.selected_objects: = ob
    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.mesh.sort_elements(type='MATERIAL', elements={'FACE'})
    bpy.ops.object.mode_set(mode = 'OBJECT')