Community
Maya Animation and Rigging
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya animation topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pythonic/MEL Way to Retarget HIK

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
robwiese149
9456 Views, 7 Replies

Pythonic/MEL Way to Retarget HIK

Hey there.

 

Using Maya 2018 here.

 

I'm trying to automate my process of adding mocap to a custom rig. I've currently written a script that duplicates the joint hierarchy and loads in my HIK preset definition. However, I can't seem to figure out a way to script out changing the "source" rig in the HIK menus with scripting. I've tried running some procedures from the following Mel files that live within "C:\Program Files\Autodesk\Maya2018\scripts\others\" folder.

 

"C:\Program Files\Autodesk\Maya2018\scripts\others\hikCharacterControlsUI.mel"

"C:\Program Files\Autodesk\Maya2018\scripts\others\hikGlobalUtils.mel"

 

These are the procedures I try to run:

# char is a variable string of the name of the HIK character from the .fbx file with the mocap on it
mel.eval('hikSetCurrentCharacter("'+char+'")') mel.eval('hikUpdateCharacterList()') mel.eval('hikSetCurrentSourceFromCharacter("'+char+'")') mel.eval('hikUpdateSourceList()')

This is the part of the UI I'm trying to change using python:

HIK.JPG

I don't get any error message but nothing changes on the UI. Any help is greatly appreciated. Thanks.

 

 

7 REPLIES 7
Message 2 of 8
robwiese149
in reply to: robwiese149

So I finally figured it out.

 

Instead of trying to input arguments into the MEL procedures with my new source rig, I dug around in the MEL files to find the actual UI element and did a simple edit command followed by a few HIK MEL procedures to update the UI and scene.

 

If you want to change your source rig in HIK via python, you can run the following python:

 

# As mentioned in the OP, you will need to source the following scripts (working in Maya 2018)
MAYA_LOCATION = os.environ['MAYA_LOCATION']
mel.eval('source "'+MAYA_LOCATION+'/scripts/others/hikGlobalUtils.mel"')
mel.eval('source "'+MAYA_LOCATION+'/scripts/others/hikCharacterControlsUI.mel"')
mel.eval('source "'+MAYA_LOCATION+'/scripts/others/hikDefinitionOperations.mel"')

# This queries all the menu items via DAG path (I believe) allSourceChar = cmds.optionMenuGrp("hikSourceList", query=True, itemListLong=True) # This will iterate over each menu item in the dropdown list until it hits the desired imported mocap rig name
# and changes the source rig to your mocap rig i = 1 for item in allSourceChar: # This is the name of the option menu that lives in the HIK window globally optMenu = "hikSourceList|OptionMenu" sourceChar = cmds.menuItem(item, query=True, label=True) # IMPORTANT! On this check, notice the space before "newSourceHere"; I found this is how the dropdown
menu in HIK stores the different strings so be sure to include that first space before your string if sourceChar == " newSourceHere": cmds.optionMenu(optMenu, edit=True, select=i) mel.eval('hikUpdateCurrentSourceFromUI()') mel.eval('hikUpdateContextualUI()') mel.eval('hikControlRigSelectionChangedCallback') break i+=1

I hope this helps. Let me know if you have any questions or suggestions.

 

 

Message 3 of 8
Anonymous
in reply to: robwiese149

It tried this script and it changed the string on the "Source" field, but it did not work.  It gave me this error when I was using Maya 2018.

file: C:/Program Files/Autodesk/Maya2018/scripts/others/hikCharacterControlsUtils.mel line 622: No object matches name: .OutputCharacterDefinition #

Message 4 of 8
skwhite
in reply to: robwiese149

Hey robwiese149

 

Not sure if you can give some help on this. Your code looks good and looks like it should work, but I'm running into the same problem as Lphan181.

 

I can see the dropdown menu change in the HIK menu, but it seems as though this error prevents hIK from actually connecting the two rigs. 

 

Can provide more context if needed...

Message 5 of 8
robwiese149
in reply to: skwhite

Hey. I don't know how much help I can be at this point. I believe I wrote this in Maya 2016 so it probably isn't compatible with any of the newer Maya versions. I haven't touched HIK in a long time and have written new tools that will bake any mocap data I have using temporary constraints from the mocap skeletons onto my custom nurbs based control rigs. 

 

HIK was too much of a black box for me coding wise, so I went a different direction.

Message 6 of 8
skwhite
in reply to: robwiese149

It does appear to be quite the pain to code around. Even using Echo All Commands isn't painting the clearest picture of what's happening in the background. I may do the same.

Message 7 of 8
robwiese149
in reply to: skwhite

Yeah, it's not easy.

 

I'd recommend doing the constraint method. The only thing you have to watch out for really is joint orientations. I had to figure out how to convert the joint orientations of the mocap rig to the my custom rig. To solve this I usually used some offset group nodes that were rotated by orders of 90 degrees in various directions of XYZ. Took some testing but eventually got there and then it just bakes it down to my nurbs controllers. 

Message 8 of 8
Anonymous
in reply to: robwiese149

FYI, to make this work with Maya 2020 and you have the error:
file: C:/Program Files/Autodesk/Maya2018/scripts/others/hikCharacterControlsUtils.mel line 622: No object matches name: .OutputCharacterDefinition #

 

You need to set the global mel character to your destination HIKCharacterNode.  I have done it at the start of my script like so:

mel.eval('global string $gHIKCurrentCharacter = "{}";'.format(destination_character))

I also get errors if the HIK menu is not open, to fix that:

mel.eval("HIKCharacterControlsTool;")

Hope this helps!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report