Using Python to save Transform Presets

Using Python to save Transform Presets

Anonymous
Not applicable
1,229 Views
3 Replies
Message 1 of 4

Using Python to save Transform Presets

Anonymous
Not applicable

I know how to save a transform preset on a node by using the Presets button in the Attribute Editor, but what I would like do is be able to create them for a node or group of nodes by using Python. I've used the Python nodePreset command to save presets but I don't know where this data or preset name is stored. When I click on Presets after using nodePreset, I do not see the saved preset in the list of available presets (as shown in the first image). This is unfortunate as I'd like to be able to manually set the node to the various presets I create automatically. 

 

What I'm looking for is the ability to replicate with Python what I can do manually on any given node (shown in the 2nd image). The code I was using below does indeed save the poses - even after closing and reopening Maya - but I have no way of setting these poses manually because the presets don't show up in the Attribute Editor. Any help would be appreciated.

import maya.cmds as cmds

loc = 'test_LOC'
pos1 = 'Default_Pose'
pos2 = 'Relaxed_Pose'
pos3 = 'Angry_Pose'

# Set the figure into the default pose
cmds.nodePreset(sv = (loc, pos1))
# Change pose to relaxed pose
cmds.nodePreset(sv = (loc, pos2))
# Change pose to angry pose
cmds.nodePreset(sv = (loc, pos3))

 

Transform Presets.png

Transform Preset - default.png

0 Likes
1,230 Views
3 Replies
Replies (3)
Message 2 of 4

jonsX942W
Enthusiast
Enthusiast

So In my experience presets are not great because of program updates and using different versions and even files so I suggest you do something like this simple little button and then in function you can add all the transform values which are in world space. I have been wanting to make a similar thing so I just used your setup as an example. This makes the UI and adds 3 buttons and then when the button is pressed it calls the function for each button and in each function has the transformation ('world coordinates")I hope this helps. 

import maya.cmds as cmds
import pymel.core as pm

getSeletcted= pm.ls(selection=True)
print (getSeletcted)




class B:
    def __init__(self):
        self.create_window()

    def create_window(self):
        if cmds.window("UI", exists=True):
            cmds.deleteUI("UI")
        win = cmds.window("UI")
        cmds.columnLayout()

        def defaultButtonPush(self):
            pm.select(getSeletcted[0])
            pm.move(-131.077, -19.021, 53.99, r=1, os=1, wd=1, a =True)
        def relaxedButtonPush(self):
            pm.select(getSeletcted[0])
            pm.move(-37.88, -93.194, 16.422, r=1, os=1, wd=1, a =True)
        def angryButtonPush(self):
            pm.select(getSeletcted[0])
            pm.move(-27.29, 14.036, -56.16, r=1, os=1, wd=1, a =True)

        cmds.button(label='Pose Default', command=defaultButtonPush)
        cmds.button(label='Pose Relaxed', command=relaxedButtonPush)
        cmds.button(label='Pose Angry', command=angryButtonPush)
        cmds.showWindow(win)


B()



 

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks @jonsX942W , but I am trying to save these presets for each control in the rig so using the method you posted, I'd have to know what those transforms were for each and then include them in the code. This tool is meant to be rig agnostic and has to set and store poses for a variety of rigs. That's why I was looking to store the transforms as a preset for each one. 

0 Likes
Message 4 of 4

jonsX942W
Enthusiast
Enthusiast

Mmmm I am confused. how can you set a preset if you don't know what to set it to? Maybe I am missing what you are trying to do with your rigs. 

0 Likes