There are a couple of scripts in one
rig = bpy.context.active_object in the other
rig = bpy.context.active_object.data.materials I'm assuming you are on the first as the second (materials one) creates the animation_data.
The objects are taken from the
context.selected_objects collection, by name, then sorted, then iterated and made active.
However if you have an object selected that doesn't have any animation_data, ie has no action with keyframes nor a driver, then the script will fail because
obj.animation_data is None and as the error says
AttributeError: 'NoneType' object has no attribute 'nla_tracks'
One fix would be to replace
objs = bpy.context.selected_objects
objs = [o for o in bpy.context.selected_object if o.animation_data]
or go straight to names
names = [o.name for o in bpy.context.selected_objects
to make sure each object, from selected_objects collection, has animation data.