How python calls and executes functions

How python calls and executes functions

1140534355
Enthusiast Enthusiast
824 Views
8 Replies
Message 1 of 9

How python calls and executes functions

1140534355
Enthusiast
Enthusiast

Hello, everyone, I'm new to python. Now I want to ask you a question. How do I restore the curve from the left to the right? I tried to modify the code: (.AttractionProfile [*]. AttractionProfile _ FloatValue ",0) but it won't restore to the right effect. Another question is how do I call and execute (def USVZ () function)in def reset ()未标题-1.jpg

def USVZ():
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.userVectorZ'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.userVectorZ'.format(o))

def reset():
    print("Reset with success")
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setAttr(each + ".weight", 1)
        cmds.setAttr(each + ".lengthWeight", 1)
        cmds.setAttr(each + ".innerRadius", 0)
        cmds.setAttr(each + ".outerRadius", 2)
        cmds.setAttr(each + ".density", 1)
        cmds.setAttr(each + ".randomAttraction", 0)
        cmds.setAttr(each + ".twist", 0)
        cmds.setAttr(each + ".randomTwist", 0)
   ##########################################################                 
        cmds.setAttr(each + ".attractionProfile[0].attractionProfile_FloatValue", 1)
        cmds.setAttr(each + ".attractionProfile[1].attractionProfile_FloatValue", 1)
        cmds.removeMultiInstance(each + ".attractionProfile[2]", b=True)       
  ############################################################                              
        cmds.setAttr(each + ".userFloat", 0)
        cmds.setAttr(each + ".userVectorX", 0)
        cmds.setAttr(each + ".userVectorY", 0)
        cmds.setAttr(each + ".userVectorZ", 0)
        cmds.setAttr(each + "USVZ()")                                                       
                                                                                                                          
                                                  

 

0 Likes
825 Views
8 Replies
Replies (8)
Message 2 of 9

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

I'm gonna need a bit more information on this attribute... On what kind of object is it? In which tab in the Attribute editor can it be found? What is the exact name?

 

Now calling a function is easy you simply write:

USVZ()

 

Now if you want to run it inside your forloop on each object your code would look like this:

def USVZ(o = None):

    inputs = cmds.listConnections('{0}.userVectorZ'.format(o), source=True, destination=False, plugs=True)
    if inputs:
        for i in inputs:
            cmds.disconnectAttr(i, '{0}.userVectorZ'.format(o))

def reset():
    print("Reset with success")
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setAttr(each + ".weight", 1)
        cmds.setAttr(each + ".lengthWeight", 1)
        cmds.setAttr(each + ".innerRadius", 0)
        cmds.setAttr(each + ".outerRadius", 2)
        cmds.setAttr(each + ".density", 1)
        cmds.setAttr(each + ".randomAttraction", 0)
        cmds.setAttr(each + ".twist", 0)
        cmds.setAttr(each + ".randomTwist", 0)
   ##########################################################                 
        cmds.setAttr(each + ".attractionProfile[0].attractionProfile_FloatValue", 1)
        cmds.setAttr(each + ".attractionProfile[1].attractionProfile_FloatValue", 1)
        cmds.removeMultiInstance(each + ".attractionProfile[2]", b=True)       
  ############################################################                              
        cmds.setAttr(each + ".userFloat", 0)
        cmds.setAttr(each + ".userVectorX", 0)
        cmds.setAttr(each + ".userVectorY", 0)
        cmds.setAttr(each + ".userVectorZ", 0)
        USVZ(o = each)  

This way you don't need to run the selection recogintion twice and you don't run through your entire selection for every loop in your for loop.

 

I hope that helps with calling the function.

Let me know the details about the Attribute you need to copy and I'm sure we'll figure that out.

If you could attach a test scene with a very simple example of what you are trying to do as a zipped .ma, that would be helpful as well.

0 Likes
Message 3 of 9

Kahylan
Advisor
Advisor
Accepted solution

I just realised, that your last post was about Yeti, and I don't have that plugin...

 

I'm not sure if yeti handles it's curve attribute the same way that other curve attributes get handeled in maya. With curve attributes on other maya objects, such as nParticles, the different curve points get stored as child attriubtes under the curve attribute and each value stores a tuple of 3 floats for the coordinates of the point.

So if I wanted to transfere a the curve that is set on the attribute ".viscosityScale" on an nParticle to the curve of the attribute ".surfaceTensionScale". I would do it something like this:

import maya.cmds as cmds
 
valuesList = cmds.getAttr("nParticleShape1.viscosityScale[*]")
for i in range(0,len(valuesList)):
    cmds.setAttr("nParticleShape1.surfaceTensionScale[{0}]".format(i), valuesList[i][0],valuesList[i][1],valuesList[i][2])

 

I don't know if curves work the same in Yeti, but this might be a place to start.

 

I hope it helps!

0 Likes
Message 4 of 9

1140534355
Enthusiast
Enthusiast

Hello, you can use the method of calling functions. My script is to set and delete key frames for the properties of curves. Now, when I call the function to delete keyframes in batches, maya will not respond for about 1 minute (when the curve is displayed in the view again). I wonder if this is caused by batch deletion or code? For curve editor, I want to know how to restore the default settings of curves instead of synchronizing from one attribute to another.

The return value of yeti curve is:setAttr"pgYetiGroom1Shape_strand_Shape165.attractionProfile[2].attractionProfile_Position" 0.455556;
setAttr "pgYetiGroom1Shape_strand_Shape165.attractionProfile[2].attractionProfile_FloatValue" 0.34;

7c29b30430d2d0a16d1eef081bb0636.png

import maya.cmds as cmds
import maya.mel as mel
import os
import shutil

def wKet():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".wgt")

def lwKet():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".lwgt")

def inr():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".inr")

def our():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".our")

def den():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".den")

def rat():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".rat")

def twt():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".twt")

def rdtw():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".rdtw")

def usf():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".usf")

def userVectorX():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".userVectorX")

def userVectorY():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".userVectorY")

def userVectorZ():
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:
        cmds.setKeyframe(each + ".userVectorZ")
                
def userF():
    guidesSelection = cmds.ls(sl=True, dag=True)
    userFiledV = cmds.floatField("userFloat", q=True, v=True)
    xV = cmds.floatField("x", query=True, v=True)
    yV = cmds.floatField("y", query=True, v=True)
    zV = cmds.floatField("z", query=True, v=True)
    print(userFiledV, xV, yV, zV)
    for each in guidesSelection:
        cmds.setAttr(each + ".userFloat", userFiledV)
        cmds.setAttr(each + ".userVectorX", xV)
        cmds.setAttr(each + ".userVectorY", yV)
        cmds.setAttr(each + ".userVectorZ", zV)                                
                                                                
####
def ClWeinht(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.weight'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.weight'.format(o))

def CLW(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.lengthWeight'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.lengthWeight'.format(o))

def INNER(o = None):  
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.innerRadius'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.innerRadius'.format(o))

def OUR(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.outerRadius'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.outerRadius'.format(o))

def DES(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.density'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.density'.format(o))   
                                
def RANA(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.randomAttraction'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.randomAttraction'.format(o))

def TWS(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.twist'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.twist'.format(o))

def RANT(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.randomTwist'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.randomTwist'.format(o)) 
                                
def USEF(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.userFloat'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.userFloat'.format(o))

def USVX(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.userVectorX'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.userVectorX'.format(o))

def USVY(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.userVectorY'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.userVectorY'.format(o))                                                                
                                                                                                                                
def USVZ(o = None):
    objects = cmds.ls(sl=True, dag=True)
    for o in objects:
        inputs = cmds.listConnections('{0}.userVectorZ'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.userVectorZ'.format(o))

def reset():
    print("Reset with success")
    guidesSelection = cmds.ls(sl=True, dag=True)
    for each in guidesSelection:        
        ClWeinht(o = each)        
        CLW(o = each)
        INNER(o = each)                                
        OUR(o = each)    
        DES(o = each)                                     
        RANA(o = each)    
        TWS(o = each)   
        RANT(o = each)                                   
        USEF(o = each)  
        USVX(o = each)    
        USVY(o = each)                                                               
        USVZ(o = each)
                                                                   
                                                                                                        
                          

############################################

if cmds.window("YetiTool", exists=True):
    cmds.deleteUI("YetiTool")

cmds.window("YetiTool", t="Yetitool",
          w=460, h=600, sizeable=True, mnb=True, mxb=False)

cmds.scrollLayout('scrollLayout')
cmds.columnLayout(adj=True)


#######################################

cmds.setParent("..")


cmds.separator(h=5)
cmds.rowColumnLayout(nc=3, cal=(1, "left"), columnWidth=[(1, 100), (2, 200), (3, 80)])
cmds.text("attribut", h=20, bgc=(0.2, 0.5, 0.5))

cmds.text("key frame",  h=20, bgc=(0.2, 0.5, 0.5))
cmds.text("del key frame", h=20, bgc=(0.2, 0.5, 0.5))

cmds.text("Weight:")

cmds.button("Set key", bgc=(1, 0.05, 0), c="wKet()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="ClWeinht()")

cmds.text("Length Weight:")

cmds.button("Set key",  bgc=(1, 0.05, 0), c="lwKet()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="CLW()")

cmds.text("Inner Radius:")

cmds.button("Set key", bgc=(1, 0.05, 0), c="inr()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="INNER()")

cmds.text("OuterRadius:")

cmds.button("Set key",  bgc=(1, 0.05, 0), c="our()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="OUR()")

cmds.text("Density:")

cmds.button("Set key", bgc=(1, 0.05, 0), c="den()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="DES()")
cmds.text("RandomAttraction:")

cmds.button("Set key", bgc=(1, 0.05, 0), c="rat()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="RANA()")

cmds.text("Twist:")

cmds.button("Set key",bgc=(1, 0.05, 0), c="twt()")
cmds.button("Cl key",bgc=(0.4, 0.2, 0.3), c="TWS()")

cmds.text("RandomTwist:")

cmds.button("Set key",bgc=(1, 0.05, 0), c="rdtw()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="RANT()")


cmds.setParent("..")
cmds.separator(h=5)  
cmds.rowColumnLayout(nc=8, w=460, columnWidth=[(1, 80)])
    
cmds.text("User Float:", w=80)
cmds.floatField("userFloat", w=55)
cmds.text("User Vector:", w=80)
cmds.floatField("x", w=55)
cmds.floatField("y", w=55)
cmds.floatField("z", w=55)

cmds.button(" confirm ", w=80,bgc=(0.1, 1, 0.1), c="userF()")
cmds.separator(h=10)
cmds.rowColumnLayout(w=460, h=400)
cmds.rowColumnLayout(nc=12, cal=(1, "left"), columnWidth=[(1, 20), 
(2, 50),(3, 50), (4, 30), (5, 50), (6, 50), (7, 5), (8, 50),
(9, 50), (10, 5), (11, 50), (12, 50)])
cmds.text("  " )

cmds.button("Set key",  bgc=(1, 0.05, 0), c="usf()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="USEF()")
    
cmds.text("  " )
cmds.button("Set key",  bgc=(1, 0.05, 0), c="userVectorX()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="USVX()")
    
cmds.text("  " )
cmds.button("Set key", bgc=(1, 0.05, 0), c="userVectorY()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="USVY()")

cmds.text("  " )
cmds.button("Set key", bgc=(1, 0.05, 0), c="userVectorZ()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="USVZ()")

cmds.setParent('..')


cmds.button("Reset", w=230, h=30, c='reset()')


cmds.showWindow("YetiTool")
0 Likes
Message 5 of 9

Kahylan
Advisor
Advisor
Accepted solution

I'm not surprised that your script takes this long, its caused by your code. You are overwriting the variable "o" in your reset function with your selections list, so it loops through the entire selection each time. Which means that the loop in your reset function runs (lengthOfSelection*12) times...

 

Here is how I would do that part of the script:

####
                                                                                                                                                                                            
def ClAttr(object = None, attr = ""):
    if object== None:
        object = cmds.ls(sl = True, dag = True, type = 'transform')
    elif type(object) != list:
        object = list(object)


    for o in object:
        inputs = cmds.listConnections('{0}.{1}'.format(o, attr), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i, '{0}.{1}'.format(o,attr))
                
def reset():
    print("Reset with success")
    guidesSelection = cmds.ls(sl=True, dag=True, type = 'transform')
    attrList = ['weight','lengthWeight','innerRadius','outerRadius','density','randomAttraction','twist','randomTwist','userFloat',"userVectorX","userVectorY","userVectorZ"]
    for each in guidesSelection:        
        for attr in attrList:                                                           
            ClAttr(object = each, attr = attr)
                                                                   
                                                                                                        
                          

############################################

if cmds.window("YetiTool", exists=True):
    cmds.deleteUI("YetiTool")

cmds.window("YetiTool", t="Yetitool",
          w=460, h=600, sizeable=True, mnb=True, mxb=False)

cmds.scrollLayout('scrollLayout')
cmds.columnLayout(adj=True)


#######################################

cmds.setParent("..")


cmds.separator(h=5)
cmds.rowColumnLayout(nc=3, cal=(1, "left"), columnWidth=[(1, 100), (2, 200), (3, 80)])
cmds.text("attribut", h=20, bgc=(0.2, 0.5, 0.5))

cmds.text("key frame",  h=20, bgc=(0.2, 0.5, 0.5))
cmds.text("del key frame", h=20, bgc=(0.2, 0.5, 0.5))

cmds.text("Weight:")

cmds.button("Set key", bgc=(1, 0.05, 0), c="wKet()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'weight')")

cmds.text("Length Weight:")

cmds.button("Set key",  bgc=(1, 0.05, 0), c="lwKet()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'lengthWeight')")

cmds.text("Inner Radius:")

cmds.button("Set key", bgc=(1, 0.05, 0), c="inr()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'innerRadius')")

cmds.text("OuterRadius:")

cmds.button("Set key",  bgc=(1, 0.05, 0), c="our()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'outerRadius')")

cmds.text("Density:")

cmds.button("Set key", bgc=(1, 0.05, 0), c="den()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'density')")
cmds.text("RandomAttraction:")

cmds.button("Set key", bgc=(1, 0.05, 0), c="rat()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'randomAttraction')")

cmds.text("Twist:")

cmds.button("Set key",bgc=(1, 0.05, 0), c="twt()")
cmds.button("Cl key",bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'twist')")

cmds.text("RandomTwist:")

cmds.button("Set key",bgc=(1, 0.05, 0), c="rdtw()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'randomTwist')")


cmds.setParent("..")
cmds.separator(h=5)  
cmds.rowColumnLayout(nc=8, w=460, columnWidth=[(1, 80)])
    
cmds.text("User Float:", w=80)
cmds.floatField("userFloat", w=55)
cmds.text("User Vector:", w=80)
cmds.floatField("x", w=55)
cmds.floatField("y", w=55)
cmds.floatField("z", w=55)

cmds.button(" confirm ", w=80,bgc=(0.1, 1, 0.1), c="userF()")
cmds.separator(h=10)
cmds.rowColumnLayout(w=460, h=400)
cmds.rowColumnLayout(nc=12, cal=(1, "left"), columnWidth=[(1, 20), 
(2, 50),(3, 50), (4, 30), (5, 50), (6, 50), (7, 5), (8, 50),
(9, 50), (10, 5), (11, 50), (12, 50)])
cmds.text("  " )

cmds.button("Set key",  bgc=(1, 0.05, 0), c="usf()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'userFloat')")
    
cmds.text("  " )
cmds.button("Set key",  bgc=(1, 0.05, 0), c="userVectorX()")
cmds.button("Cl key",  bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'userVectorX')")
    
cmds.text("  " )
cmds.button("Set key", bgc=(1, 0.05, 0), c="userVectorY()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'userVectorY')")

cmds.text("  " )
cmds.button("Set key", bgc=(1, 0.05, 0), c="userVectorZ()")
cmds.button("Cl key", bgc=(0.4, 0.2, 0.3), c="ClAttr(attr = 'userVectorZ')")

cmds.setParent('..')


cmds.button("Reset", w=230, h=30, c='reset()')


cmds.showWindow("YetiTool")

Now as you can see, I replaced your 12 different functions for deleting keys, with one function that has a kwarg for the string that needs to be changed. I would suggest you do the same for all your setKey functions (with exception of "userF()"), because right now, your script is really cluttered and hard to understand...

0 Likes
Message 6 of 9

Kahylan
Advisor
Advisor
Accepted solution

Now to the curve attribute again. From what you posted I can see that Yetu uses a standart curve attribute, so I can tell you how to do it.

But first, you need to know how curves like this work. So you can understand what I do and change parameters if I don't get it 100% right.

A curve like this the curve is stored in an attribute (lets call it: "test"), this attribute then has sub attributes for each point on the curve (point 0: "test[0]", point 1: "test[1]", and so on...) and each of those attributes has three child attributes that store position on the X-Axis, position on the Y-Axis and interpolationtype to the right side of the point ("test[x].test_position","test[x].test_floatValue","test[x].test_interp"). To set all those sub attributes on a point at once you can use this synthax:

cmds.setAttr("objectName.test[indexOfPoint]",positionValue,floatValue,interpolationEnumValue)

So if I wanted to set the first point on my attribute "test" on my object "obj" to be in the top left corner, I could use:

cmds.setAttr("obj.test[0]",0.0,1.0,1)

 

to delete an unwanted point, you can use:

cmds.removeMultiInstance("objecName.test[indexOfPoint]", b= True )

 So deleting point 5 on attribute "test" on object "obj":

cmds.removeMultiInstance("obj.test[5]", b= True )

 

So to restore your default value, you need to know two things:

1) How many points there are in the beginning

2) What the position, floatValue and interp on each point is in the beginning

 

So if your default value was 2 points, one in the top left corner and one in top right corner, you could use this function:

def resetCurve(attr = "",numberPoints = 1, values = [(0,1,1)]):
    if len(values) < numberPoints:
        print("not enough values supplied")
        return

    sel = cmds.ls(sl = True)
    for s in sel:
        valuesList = cmds.getAttr("{0}.{1}[*]".format(s,attr))
        
        for p in range(0,numberPoints):
            cmds.setAttr("{0}.{1}[{2}]".format(s,attr,p), values[p][0],values[p][1],values[p][2])
    
    if len(valuesList) > numberPoints:
        for i in range(numberPoints, len(valuesList)):
            cmds.removeMultiInstance("{0}.{1}[{2}]".format(s,attr,i), b= True )
 

resetCurve(attr = "attractionProfile", numberPoints = 2, values = [(0,1,1),(1,1,1)])   

 

I hope it helps!

0 Likes
Message 7 of 9

1140534355
Enthusiast
Enthusiast
Accepted solution
Hello, I understand how key frames modify and call functions, but why do curves define that cmds.ls(sl = True) cannot reset all selected curves? I quoted cmds.ls in resetCurve () still only the last selected object curve can be reset.
0 Likes
Message 8 of 9

Kahylan
Advisor
Advisor
Accepted solution

I had the wrong indentation level on the part of the function where obsolete points get deleted...

This should work for all selected.

def resetCurve(attr = "",numberPoints = 1, values = [(0,1,1)]):
    if len(values) < numberPoints:
        print("not enough values supplied")
        return

    sel = cmds.ls(sl = True)
    for s in sel:
        valuesList = cmds.getAttr("{0}.{1}[*]".format(s,attr))
        
        for p in range(0,numberPoints):
            cmds.setAttr("{0}.{1}[{2}]".format(s,attr,p), values[p][0],values[p][1],values[p][2])
    
        if len(valuesList) > numberPoints:
            for i in range(numberPoints, len(valuesList)):
                cmds.removeMultiInstance("{0}.{1}[{2}]".format(s,attr,i), b= True )
     

resetCurve(attr = "attractionProfile", numberPoints = 2, values = [(0,1,1),(1,1,1)]) 

I hope it helps!

0 Likes
Message 9 of 9

1140534355
Enthusiast
Enthusiast
Accepted solution
thank you
0 Likes