Search code examples
pythonmayacurvebezier

Maya Python How do I make a curve out of multiple collected points in a for loop


I have a forloop to get all the positions in a list of locators, I need this info to create a curve of all the points. but when I put the cmds.curve in the forloop it creates several curves and when I put it outside of it there only is one curve on the last position in the list. Does someone have a solution for this?

    for locator in state:

        print("\t", locator)
        translate_x_value = cmds.getAttr("%s.translateX" % locator)
        translate_y_value = cmds.getAttr("%s.translateY" % locator)
        translate_z_value = cmds.getAttr("%s.translateZ" % locator)


        cmds.curve(p=translate_x_value,translate_y_value,translate_z_value))

Solution

  • You may have to feed your cmds.curve() outside the loop :

    locatorOrder = ['loc1', 'loc2'...etc]
    positionOrder = [cmds.pointPosition(i) for i in locatorOrder]
    
    cmds.curve(p=positionOrder) # draw the curve between locators