<commit_before><commit_msg>First commit: * BlenderMakeBoneNamesUnique.py - used to prepare for exporting duplicated armatures to Collada<commit_after>
'''

Gives each bone a unique name.
Useful for e.g., preparing duplicated armatures for export to Collada.

'''

import bpy

# Maps from a bone instance to its name.
boneAndNames = {}

# First, build the map from bone instances to the bone's name.
for ob in bpy.data.objects:
	if ob.type == 'ARMATURE':
		armature = ob.data
		for bone in armature.bones:
			boneAndNames[bone] = bone.name

beforeBoneNamesWithDuplicates = len(boneAndNames.values())
beforeBoneNamesUnique = len(set(boneAndNames.values()))
print('BEFORE: %d bone names, %d unique' % (beforeBoneNamesWithDuplicates, beforeBoneNamesUnique))

# Finally, give each bone a unique name.
for ob in bpy.data.objects:
	if ob.type == 'ARMATURE':
		armature = ob.data
		for bone in armature.bones:
			if bone.name in boneAndNames.values():
				newName = armature.name + '.' + bone.name
				bone.name = newName
				boneAndNames[bone] = newName

afterBoneNamesWithDuplicates = len(boneAndNames.values())
afterBoneNamesUnique = len(set(boneAndNames.values()))
print('AFTER: %d bone names, %d unique' % (afterBoneNamesWithDuplicates, afterBoneNamesUnique))
{'fraction_non_alphanumeric': 0.10589171974522293, 'fraction_numerical': 0.0, 'mean_word_length': 4.929245283018868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4012858', 'n_tokens_mistral': 425, 'n_tokens_neox': 405, 'n_words': 120}