Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Adding keyframes and deleting keyframes about Attraction Profile

Adding keyframes and deleting keyframes about Attraction Profile

1140534355
Enthusiast Enthusiast
322 Views
2 Replies
Message 1 of 3

Adding keyframes and deleting keyframes about Attraction Profile

1140534355
Enthusiast
Enthusiast

Hello, everyone, I want to set the key frame of the selected point on ramp Curve and delete the key frame. I used cmds.ls(sl = True) and found that the point will not be selected. How should I use python to select the single vertex above?714f2c8608d719479b2484b8fd31009.png

def Cl_Key():  
    objects = cmds.ls(sl = True, dag = True)
    set = cmds.ls(sl = True)    
    for o in objects:
        for s in set:        
            inputs01 = cmds.listConnections('{0}.attractionProfile[{}].attractionProfile_Position'.format(o, s), source=True, destination=False, plugs=True)
            inputs02 = cmds.listConnections('{0}.attractionProfile[{}].attractionProfile_FloatValue'.format(o,s), source=True, destination=False, plugs=True)        
            inputs03 = cmds.listConnections('{0}.attractionProfile[{}].attractionProfile_Position'.format(o,s), source=True, destination=False, plugs=True)                                              
            if inputs01:
                for i in inputs01:
                    cmds.disconnectAttr(i,'{0}.attractionProfile[{}].attractionProfile_Position'.format(o,s))
            if inputs02:
                for s in inputs02:
                    cmds.disconnectAttr(s,'{0}.attractionProfile[{}].attractionProfile_FloatValue'.format(o,s))
            if inputs03:
                for l in inputs03:
                    cmds.disconnectAttr(l,'{0}.attractionProfile[{}].attractionProfile_Interp'.format(o,s))                                                                

def set_key():
    guidesSelection = cmds.ls(sl=True,dag=True)
    set = cmds.ls(sl = True)        
    for each in guidesSelection:
       for i in set :         
        cmds.setKeyframe(each + ".atpr[{}].atprp".format(i))
        cmds.setKeyframe(each + ".atpr[{}].atprfv".format(i))
        cmds.setKeyframe(each + ".atpr[{}].atpri".format(i))
0 Likes
Accepted solutions (1)
323 Views
2 Replies
Replies (2)
Message 2 of 3

jmreinhart
Advisor
Advisor

So it "might" be possible to do that but it would be very hacky.

 

You can't directly query the selected key from a gradientControl (The ramp widget).

 

However you could do this:

  1. Get the name of the floatField from the attributeEditor. This is the one step that I'm not really sure how to do. You should look around to see if you can find other posts about getting the names of widgets in the default Maya UI.
  2. Get the position and floatValues for all the keys in the ramp using getAttr (and record them).
  3. Set the floatField to a new value.
  4. Get the new position and floatValues for all the keys in the ramp using getAttr (and record them).
  5. Compare those two lists of data to see which one changed, that is the index of the selected key.
  6. Set the value in the floatField back to what it was.
jmreinhart_2-1666615509816.png

 

 

 

 

 

 

 

 

Message 3 of 3

jmreinhart
Advisor
Advisor
Accepted solution

Did some digging this gets you these, don't have time to check which returned value is which at the moment.

 

layoutChildren =  cmds.layout("valueRampForm", q = True, childArray = True) 

jmreinhart_0-1666617196344.png

 

 

0 Likes