Untitled

 avatar
unknown
plain_text
a year ago
2.4 kB
5
Indexable
import pymel.core as pm
print("hello world")

def colorPicker():
    result = pm.colorEditor()
   
    colorList =result.split(" ")
   
    colorList = [float(v) for v in colorList if v != ""]
    return colorList[:-1]
   
def createControl(ctrlName="myControl", addInConstraint=False, myColor = [1,1,0]):
       
    # create a nurbs circle
    makeCircleResult = pm.circle(name=f"{ctrlName}_ctrl")
   
    myCtrl = makeCircleResult[0]
   
    # delete history on controller
    pm.delete(makeCircleResult[1])
   
    # create a rest for controller
    myRest = pm.group(name=f"{ctrlName}_rest", empty=True)
   
    # [OPTIONAL] create inConstraint
    if addInConstraint == True:
        myInConstraint = pm.group(name=f"{ctrlName}_inCns", empty=True)
       
    # parent controller under rest
    pm.parent(myCtrl, myRest)
   
    # IF WE HAVE inConstraint, we parent under inCons
    if addInConstraint == True:
        pm.parent(myRest, myInConstraint)
   
    # set controller color
    #    Object Oriented Method
    pm.setAttr(myCtrl.overrideEnabled, 1)
   
    pm.setAttr(myCtrl.overrideRGBColors, 1)
   
    pm.setAttr(myCtrl.overrideColorR, myColor[0])
    pm.setAttr(myCtrl.overrideColorG, myColor[1])
    pm.setAttr(myCtrl.overrideColorB, myColor[2])



######## setup
moduleName = None
c = [1, 1, 0] #yellow  
safetyVariable = 10
done = False
########
 
# promptDialogue
i = 0
while done == False and i < safetyVariable:
   
    result = pm.promptDialog(title ="Control Maker",
    message ="Enter a name for your control... if you dare!",
    button = ["Add Control", "Add Control with InCns", "Set Control Color"],
    text = moduleName)

    i +=1
    if result == "Add Control":
   
        moduleName = pm.promptDialog(query=True, text=True)
        createControl(moduleName, False, c)
        done = True
       
    elif result == "Add Control with InCns":
         moduleName = pm.promptDialog(query=True, text=True)
         createControl(moduleName, True, c)
         done = True
             
    elif result == "Set Control Color":
         moduleName = pm.promptDialog(query=True, text=True)
         c = colorPicker()
         print(c)
       
    else:
   
        print("Coward.")
        done = True
       
# [add ctrl, add ctrl with inCns, set color]
Editor is loading...
Leave a Comment