Skip to content

Instantly share code, notes, and snippets.

@yamahigashi
Last active February 19, 2019 10:15
Show Gist options
  • Save yamahigashi/d6f3df5cd2c3e00a9f90bcc42fb5152d to your computer and use it in GitHub Desktop.
Save yamahigashi/d6f3df5cd2c3e00a9f90bcc42fb5152d to your computer and use it in GitHub Desktop.
def load_hik_animation_into_current_character(source_file_path=None, character=None):
if not source_file_path:
source_file_path = cmds.fileDialog2(
fileFilter="Scene Files (*.ma *.mb *.fbx);;Maya ASCII (*.ma);;Maya Binary (*.mb);;Fbx file(*.fbx)",
fileMode=1,
caption="Select animation source file.",
)
if not source_file_path:
raise Exception("source_file_path not found")
if isinstance(source_file_path, list):
for fp in source_file_path:
load_hik_animation_into_current_character(fp, character)
return
if not character:
current_character = mel.eval("hikGetCurrentCharacter();")
else:
current_character = character
if source_file_path.endswith("mb"):
typ = "mayaBinary"
elif source_file_path.endswith("ma"):
typ = "mayaAscii"
elif source_file_path.lower().endswith("fbx"):
typ = "FBX"
else:
raise Exception("'{}' has unknown file extension".format(source_file_path))
cmds.file(source_file_path, typ=typ, r=True, mergeNamespacesOnClash=False, namespace="tmp_load_hik")
source_character_nodes = cmds.ls(typ="HIKCharacterNode") or []
source_character_nodes = list(filter(lambda x: x.startswith("tmp_load_hik"), source_character_nodes))
if not source_character_nodes:
raise Exception("Character node not found in the source fbx: {}".format(source_file_path))
source_character = source_character_nodes[0]
mel.eval("HIKCharacterControlsTool;")
mel.eval("hikSelectCurrentCharacter(\"{}\");".format(current_character))
mel.eval("hikSetCharacterInput(\"{}\", \"{}\");".format(current_character, source_character))
mel.eval("hikUpdateSourceList; hikUpdateContextualUI;")
mel.eval("hikBakeCharacter(0);")
# cmds.file(unloadReference="tmp_load_hikRN")
# cmds.file(source_file_path, removeReference=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment