Last active
September 6, 2023 18:29
-
-
Save thismusicdude/bc56759ffeec339eb87df3848a4d1d3c to your computer and use it in GitHub Desktop.
Maximo Blender Name Converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
# _______ ______ __ __ _______ _______ _______ __ __ ______ | |
# | _ || _ | | |_| || _ || || || | | || _ | | |
# | |_| || | || | || |_| ||_ _|| ___|| | | || | || | |
# | || |_||_ | || | | | | |___ | |_| || |_||_ | |
# | || __ || || | | | | ___|| || __ | | |
# | _ || | | || ||_|| || _ | | | | |___ | || | | | | |
# |__| |__||___| |_||_| |_||__| |__| |___| |_______||_______||___| |_| | |
# | |
# by Max Schmitt (Divirad - Kepper, Lösing, Schmitt GbR | |
# v0.3 | |
# | |
# License: MIT License | |
# Copyright © 2023 Max Schmitt (Divirad - Kepper, Lösing, Schmitt GbR | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the “Software”), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is furnished | |
# to do so, subject to the following conditions: | |
# The above copyright notice and this permission notice shall be included in | |
# all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF | |
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
class RenameToolPanel(bpy.types.Panel): | |
"""Creates a Panel in the Object properties window""" | |
bl_label = 'Armateur (Name converter)' | |
bl_idname = 'PT_RenameTool' | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'UI' | |
bl_category = 'Tool' | |
def draw(self, context): | |
layout = self.layout | |
obj = context.object | |
row = layout.row() | |
row.operator('object.from_mixamo') | |
row = layout.row() | |
row.operator('object.to_mixamo') | |
class ToMixamo(bpy.types.Operator): | |
bl_idname = 'object.from_mixamo' | |
bl_label = 'To Mixamo' | |
def execute(self, context): | |
convert_to_mixamo() | |
self.report({'INFO'}, "Armature was renamed to Blender!") | |
return {'FINISHED'} | |
class ToBlender(bpy.types.Operator): | |
bl_idname = 'object.to_mixamo' | |
bl_label = 'To Blender' | |
def execute(self, context): | |
convert_to_blender() | |
self.report({'INFO'}, "Armature was renamed to Maximo!") | |
return {'FINISHED'} | |
# | |
def convert_to_blender(): | |
# go through all armature objects | |
for obj in bpy.context.scene.objects: | |
# if armature object | |
if obj.type == 'ARMATURE': | |
# select object into view layer | |
# to ensure that the armature is in the active scene | |
bpy.context.view_layer.objects.active = obj | |
# go through all bones of armature | |
for bone in obj.pose.bones: | |
# check naming condition | |
if not bone.name.endswith('.L') and not bone.name.endswith('.R'): | |
if bone.name.startswith('Left'): | |
bone.name = bone.name + '.L' | |
if bone.name.startswith('Right'): | |
bone.name = bone.name + '.R' | |
# to mixamo | |
def convert_to_mixamo(): | |
# go through all armature objects | |
for obj in bpy.context.scene.objects: | |
# if armature object | |
if obj.type == 'ARMATURE': | |
# select object into view layer | |
# to ensure that the armature is in the active scene | |
bpy.context.view_layer.objects.active = obj | |
# go through all bones of armature | |
# Example: LeftUpperLeg.R => RightUpperLeg | |
# Example: RightUpperLeg.R => RightUpperLeg | |
for bone in obj.pose.bones: | |
if bone.name.endswith('.R'): | |
bone.name = bone.name.replace('.R', '').replace('Left','Right') | |
elif bone.name.endswith('.L'): | |
bone.name = bone.name.replace('.L', '').replace('Right','Left') | |
def register(): | |
bpy.utils.register_class(RenameToolPanel) | |
bpy.utils.register_class(ToMixamo) | |
bpy.utils.register_class(ToBlender) | |
def unregister(): | |
bpy.utils.unregister_class(RenameToolPanel) | |
bpy.utils.unregister_class(ToMixamo) | |
bpy.utils.unregister_class(ToBlender) | |
if __name__ == '__main__': | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment