acoolrocket

Blender - Inherit parent null name to children meshes

Sep 30th, 2026
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import bpy
  2.  
  3. # Collect mesh objects that have an EMPTY (null) as their direct parent
  4. parent_to_meshes = {}
  5.  
  6. for obj in bpy.data.objects:
  7. if obj.type == "MESH" and obj.parent and obj.parent.type == "EMPTY":
  8. parent = obj.parent
  9. parent_to_meshes.setdefault(parent, []).append(obj)
  10.  
  11. # Rename meshes based on their direct parent's name
  12. for parent, meshes in parent_to_meshes.items():
  13. # Sort by original name to ensure predictable numbering
  14. meshes.sort(key=lambda o: o.name)
  15.  
  16. for index, mesh_obj in enumerate(meshes):
  17. if index == 0:
  18. mesh_obj.name = parent.name
  19. else:
  20. mesh_obj.name = f"{parent.name}_{index}"
Advertisement
Add Comment
Please, Sign In to add comment