def clearAll(layout, *args):
"""clears the selected text scroll list"""
cmds.textScrollList(widgets[layout], e=True, ra=True)
python类text()的实例源码
def customUI(self):
cmds.text("put UI stuff here for options")
path = cmds.internalVar(upd=True) + "default.txt"
self.widgets["destinationTFBG"] = cmds.textFieldButtonGrp(l="destination", bl="<<<", cal=([1,"left"], [2,"left"], [3,"left"]), cw3=(65,275, 50), tx=path, bc=self.getLocation)
def extendUI(*args):
"""UI for the script"""
#UI
if cmds.window("curbWin", exists=True):
cmds.deleteUI("curbWin")
cmds.window("curbWin", t="zbw_polyExtender", w=200, h=200)
cmds.columnLayout("colLO")
cmds.frameLayout("topFrame", l="Covert Edge", cll=True, bgc=(.2,.2,.2))
cmds.text("Select poly edge to convert")
cmds.button("convertBut", l="Convert!", w=200, h=30, bgc=(.8, .8,.6), c=convertEdge)
cmds.separator(h=5)
cmds.setParent("colLO")
cmds.frameLayout("midFrame", l="Create Poly", cll=True, bgc=(.2,.2,.2))
cmds.text("Select curve")
cmds.separator(h=5)
cmds.textFieldGrp("name", l="Name", w=200, cw=[(1,30), (2,170)], tx="newPoly")
cmds.checkBox("curbCB", l="Positive Direction", v=True)
# cmds.checkBox("bumpCB", l="Add vertical hump?", v=True)
cmds.floatFieldGrp("curbFFG", l="Curb Width", cal=((1, "left"),(2,"left")), cw=([1,75],[2,50]), v1=10)
cmds.intFieldGrp("UDivIFG", l="Width Subdivisions", cal=((1, "left"),(2,"left")), cw=([1,75],[2,50]), v1=1)
cmds.intFieldGrp("VDivIFG", l="Length Subdivisions", cal=((1, "left"),(2,"left")), cw=([1,75],[2,50]), v1=1)
cmds.checkBox("polyHistory", l="Keep history on final poly?", v=False)
cmds.checkBox("history", l="Keep history objects?", v=True, cc=enableHistory)
cmds.separator(h=5)
cmds.button("curbBut", l="Create Curb", h=40, w=200, bgc=(.6, .8, .6), c=extendPoly)
cmds.showWindow("curbWin")
cmds.window("curbWin", e=True, h=150, w=200)
def toggleFile(*args):
sel = cmds.radioButtonGrp(widgets["fileRBG"], q=True, sl=True)
if sel == 1:
cmds.text(widgets["selFile"], e=True, en=False)
def zbw_mmDeleteConfirm():
if (cmds.text("mmTextConfirm", q=True, ex=True)):
cmds.deleteUI("mmTextConfirm")
cmds.deleteUI("mmConfirmSep")
def zbw_mmDeleteLast(*args):
"""
deletes the last pair of attr, obj text fields in the UI
"""
children = cmds.rowColumnLayout("mmRCLayout" , q=True, ca=True)
if children:
numChildren = len(children)
lastTFG = "attr" + str(numChildren/2)
lastTFBG = "obj" + str(numChildren/2)
cmds.deleteUI(lastTFG)
cmds.deleteUI(lastTFBG)
else:
pass
def zbw_mmChangeConnectAttr(base, attr, obj, *args):
#get that from the text field
newAttr = cmds.textFieldGrp("zbw_mmChangeAttrTFG", q=True, tx=True)
#delete old attr
cmds.deleteAttr(attr)
#create new attr
cmds.addAttr(base, at="message", ln=newAttr)
#create connection to obj in new attr
cmds.connectAttr((obj+".message"), (base+"."+newAttr), f=True)
#when you delete, then run the whole proc again afterwards (to clean up the nums)
cmds.deleteUI('zbw_mmChangeAttrUI', window=True)
cmds.windowPref('zbw_mmChangeAttrUI', remove=True)
cmds.deleteUI("mmRCListLayout")
zbw_mmListCurrentMessages("mmListMessages")
def extrudeUI():
if cmds.window("curveExtrudeWin", exists=True):
cmds.deleteUI("curveExtrudeWin")
w, h = 300, 220
widgets["win"] = cmds.window("curveExtrudeWin", w=w, h=h)
widgets["CLO"] = cmds.columnLayout(w=w, h=h)
widgets["text1"] = cmds.text(l="Name the rig to be created:")
cmds.separator(h=5)
widgets["nameTFG"] = cmds.textFieldGrp(l="Rig Name: ", cal=[(1, "left"),(2, "left")],cw=[(1, 50),(2, 245)])
cmds.separator(h=5)
widgets["text2"] = cmds.text(l="Select the path curve.\nOptionally, "
"then select profile crv and the cap rig in that order\n"
"Note that cap rig and profile curve should be y up!", al="left")
cmds.separator(h=5)
widgets["extrBut"] = cmds.button(l="Create Extrusion Rig!", w=300, h=35, bgc = (.4, .5,.4), c=prepExtrude)
cmds.separator(h=10)
widgets["text3"] = cmds.text(l="Once you've attached a material :\nselect the control, then any place2DTexture nodes", al="left")
cmds.separator(h=5)
widgets["textureBut"] = cmds.button(l="Connect Ctrl to place2DTexture nodes!", w=300, h=35, bgc = (.25, .35, .5), c = connectTexture)
cmds.window(widgets["win"], e=True, w=w, h=h)
cmds.showWindow(widgets["win"])
def import_anim_UI():
width = 400
if cmds.window("impAnimWin", exists=True):
cmds.deleteUI("impAnimWin")
widgets["win"] = cmds.window("impAnimWin", t="Import anim files", w=width, h=400, rtf=True)
# widgets["clo"] = cmds.columnLayout()
widgets["mainTLO"] = cmds.tabLayout()
widgets["impCLO"] = cmds.columnLayout("Import Anim")
cmds.text("1. choose the folder where your anim clips live,\n2. select the objs in scene to apply to\n3. 'random' will start anim in frame range\n4. select anim clips from list to randomly apply to objs\n5. press button to apply",al="left")
cmds.separator(h=10)
widgets["impPathTFG"] = cmds.textFieldButtonGrp(l="Anim Path:", bl="<<<", cal = ([1, "left"], [2, "left"], [3, "right"]), cw=([1, 75], [2, 275], [3, 40]), bc=partial(get_path, "import", "impPathTFG"), cc=populate_tsl)
widgets["randRBG"] = cmds.radioButtonGrp(l="Insert Placement:", nrb=2, l1="Random Start", l2="At current Frame", sl=1, cal=([1, "left"], [2,"left"], [3,"left"]), cw=([1,100], [2, 100], [3, 100]), cc=partial(toggle_enable, "randRBG", "rangeIFG"))
widgets["rangeIFG"] = cmds.intFieldGrp(l="Random Start Range:", nf=2, v1=0, v2=100, cw=([1, 120], [2, 50], [3, 50]), cal=([1, "left"], [2, "left"], [3, "left"]))
widgets["delCBG"] = cmds.checkBoxGrp(l="Delete subsequent keys?", v1=True, cal=([1, "left"], [2, "left"]), cw=([1, 130], [2, 20]))
cmds.separator(h=10)
widgets["animTSL"] = cmds.textScrollList(w=400, h=150, allowMultiSelection=True)
cmds.separator(h=10)
widgets["importBut"] = cmds.button(l="Import random anim from selection", h=40, w=width, bgc=(.5, .8, .5), c=import_animation)
cmds.setParent(widgets["mainTLO"])
widgets["expCLO"] = cmds.columnLayout("Export Anim")
cmds.text("1. Select the obj 2. choose a path and name the anim\n3. choose range and hierarchy 4. press button!", al="left")
cmds.separator(h=10)
widgets["expPathTFG"] = cmds.textFieldButtonGrp(l="Export Path:", bl="<<<", cal = ([1, "left"], [2, "left"], [3, "right"]), cw=([1, 75], [2, 275], [3, 40]), bc=partial(get_path, "export", "expPathTFG"))
widgets["nameTFG"] = cmds.textFieldGrp(l="Animation Name:", cw=([1, 100], [2, 250]), cal=([1, "left"], [2, "left"]))
widgets["selRBG"] = cmds.radioButtonGrp(l="Hierarchy:", nrb=2, l1="Selection Only", l2="Below", sl=2, cal=([1, "left"], [2,"left"], [3,"left"]), cw=([1,75], [2, 100], [3, 100]))
widgets["expRngRBG"] = cmds.radioButtonGrp(l="Time Range:", nrb=2, l1="Start_End", l2="All", sl=2, cal=([1, "left"], [2,"left"], [3,"left"]), cw=([1,75], [2, 100], [3, 100]), cc=partial(toggle_enable, "expRngRBG", "expRngIFG"))
widgets["expRngIFG"] = cmds.intFieldGrp(nf=2, en=False, l="Start_End", v1=1, v2=10, cal=([1, "left"], [2,"left"], [3,"left"]), cw=([1,75], [2, 100], [3, 100]))
cmds.separator(h=10)
widgets["exportBut"] = cmds.button(l="Export anim from selection", h=40, w=width, bgc=(.5, .8, .5), c=export_animation)
cmds.window(widgets["win"], e=True, w=5, h=5, rtf=True)
cmds.showWindow(widgets["win"])
def populate_tsl(*args):
"""populates the list from the imp text field grp path"""
path = cmds.textFieldButtonGrp(widgets["impPathTFG"], q=True, tx=True)
if not path or not os.path.isdir(path):
cmds.warning("Couldn't find that path ({0})!".format(path))
return()
animFiles = [x for x in os.listdir(path) if x.rpartition(".")[2] == "anim"]
if not animFiles:
return()
animFiles.sort()
for af in animFiles:
cmds.textScrollList(widgets["animTSL"], e=True, a=af)
def wireRigUI (*args):
if cmds.window("wireRigWin", exists = True):
cmds.deleteUI("wireRigWin")
widgets["win"] = cmds.window("wireRigWin", t="zbw_wireRig", w=300, h=250)
widgets["mainCLO"] = cmds.columnLayout()
widgets["topFLO"] = cmds.frameLayout(l="Convert Poly Edges",cll=True, cl=True)
widgets["topCLO"] = cmds.columnLayout()
widgets["convertBut"] = cmds.button(l="convert selected poly edge to curve", w=300, bgc = (.8,.8,0), c=convertEdge)
cmds.separator(h=20, style="single")
widgets["reverseBut"] = cmds.button(l="reverse direction of selected curve", w=300, bgc = (.8,.5,0), c=reverseCrv)
cmds.setParent(widgets["mainCLO"])
widgets["botFLO"] = cmds.frameLayout(l="Create Wire Rig", cll=True)
widgets["botCLO"] = cmds.columnLayout()
widgets["numCtrlIFG"] = cmds.intFieldGrp(l="Number of Ctrls:", v1=5, cal=[(1, "left"), (2, "left")], cw=[(1, 150),(3, 75)])
widgets["hierCBG"] = cmds.checkBoxGrp(ncb=1, l1 = "Put Ctrls in hierarchy?", v1=True, en=True)
widgets["nameTFG"] = cmds.textFieldGrp(l="Wire Rig Name:", w=300, tx="wireCtrl1", cal=[(1, "left")])
widgets["scaleFFG"] = cmds.floatFieldGrp(l="Control scale:", v1=1.0, cal=[(1, "left"), (2, "left")], cw=[(1, 150),(3, 75)])
cmds.separator(h=30, style="single")
widgets["textText"] = cmds.text("Select geo, then curve, then button below", al="center")
widgets["rigBut"] = cmds.button(l="Create Wire Rig", w= 300, h=40, bgc= (0, .5, 0), c=createWireDef)
cmds.showWindow(widgets["win"])
#option to pull curve from edges
def audioUI():
"""UI for the whole thing"""
if (cmds.window("audioWin", exists=True)):
cmds.deleteUI("audioWin")
widgets["win"] = cmds.window("audioWin", t="zbw_audioManager", w=300, h=260)
widgets["mainCLO"] = cmds.columnLayout()
widgets["getAudioBut"] = cmds.button(l="Get All Audio In Scene", w=300, h=30, bgc=(.6, .6, .8), c=getAudio)
cmds.text("Double-click item in list to enable sound and select it", al="left")
widgets["audioTSL"] = cmds.textScrollList(h=100, w=300, dcc=selectAudio)
widgets["buttonRCLO"] = cmds.rowColumnLayout(nc=2)
widgets["deleteSelBut"] = cmds.button(l="Delete Selected", w=150, h=20, bgc=(.8,.6,.6), c=deleteSelected)
widgets["deleteAllBut"] = cmds.button(l="Delete All Audio", w=150, h=20, bgc=(.8,.4,.4), c=deleteAll)
cmds.setParent(widgets["mainCLO"])
cmds.separator(h=20)
widgets["newAudioBut"] = cmds.button(l="Import New Audio File!", w=300, h=30, bgc=(.6,.8,.6), c=importAudio)
cmds.separator(h=20)
widgets["offsetRCLO"] = cmds.rowColumnLayout(nc=2, cw=([1,175], [2, 125]), cal=([1,"left"], [2,"left"]))
widgets["offsetIFG"] = cmds.intFieldGrp(l="Offset Selected By ", v1=1, cal=([1,"left"], [2,"left"]), cw=([1,100],[2,50]))
widgets["offsetBut"] = cmds.button(l="Offset!", w=100, h=30, bgc=(.6,.8,.8), c=offsetAudio)
cmds.showWindow(widgets["win"])
cmds.window(widgets["win"], e=True, w=300, h=260)
def getTypeText(*args):
"""
gets text
"""
txt = cmds.textFieldButtonGrp(widgets["typeTFBG"], q=True, tx=True)
if not txt: # if no entry
cmds.warning("node type: Nothing entered!")
return(None)
if re.match('^[a-zA-Z0-9_]+$',txt): # if we have valid text
return(txt)
else: # if we have bad text
cmds.warning("Some bad characters in there. Please use numbers, letters, or underscores!")
return(None)
def getSearchText(*args):
"""
gets text
"""
txt = cmds.textFieldGrp(widgets["stringSearchTFG"], q=True, tx=True)
if not txt: # if no entry
cmds.warning("string search: Nothing entered!")
return(None)
if re.match('^[a-zA-Z0-9_]+$',txt): # if we have valid text
return(txt)
else: # if we have bad text
cmds.warning("Some bad characters in there. Please use numbers, letters, or underscores!")
return(None)
def fillMenuText(text, *args):
cmds.textFieldButtonGrp(widgets["typeTFBG"], e=True, tx=text)
def getObj(tfg, *args):
"""gets selected obj and adds it to the text field"""
sel = cmds.ls(sl=True, type="transform", l=True)
if (len(sel)) == 1:
cmds.textFieldGrp(tfg, e=True, tx=sel[0])
#--------if layout == the space switch text grp
clearList()
else:
cmds.warning("yo. Select one object as your space switch control")
def addToField(num, *args):
"""calls a file dialog to get a path and adds it to the selected field"""
#set the field to add to
textField = widgets["path%s"%num]
#call up browser to look for paths
path = cmds.fileDialog2(fm=3)[0]
#add text
if path:
cmds.textFieldButtonGrp(textField, e=True, tx=path)
def append(*args):
paths = []
#get paths
path1 = cmds.textFieldButtonGrp(widgets["path1"], q=True, tx=True)
path2 = cmds.textFieldButtonGrp(widgets["path2"], q=True, tx=True)
path3 = cmds.textFieldButtonGrp(widgets["path3"], q=True, tx=True)
paths.append(path1)
paths.append(path2)
paths.append(path3)
#append path with text from fields
check = 0
for path in paths:
if path:
if os.path.isdir(path):
if path in sys.path:
cmds.warning("'%s' is already in sys.path. Skipping!"%path)
else:
sys.path.append(path)
check += 1
else:
cmds.warning("%s is not an existing path and wasn't added to sys.path"%path)
if check > 0:
cmds.warning("Added paths! Check the 'View Paths' tab to see them")
#delete the text
cmds.textFieldButtonGrp(widgets["path1"], e=True, tx="")
cmds.textFieldButtonGrp(widgets["path2"], e=True, tx="")
cmds.textFieldButtonGrp(widgets["path3"], e=True, tx="")
#refresh the path list on second tab
refresh()
def clearValues(*args):
"""clears the text fields"""
cmds.textFieldButtonGrp(widgets["path1"], e=True, tx="")
cmds.textFieldButtonGrp(widgets["path2"], e=True, tx="")
cmds.textFieldButtonGrp(widgets["path3"], e=True, tx="")
def setupRLUI():
if cmds.window("RLWin", exists=True):
cmds.deleteUI("RLWin")
widgets["win"] = cmds.window("RLWin", t="zbw_setupRL", w=200, h=400)
widgets["mainCL"] = cmds.columnLayout(w=200)
widgets["mainFrame"] = cmds.frameLayout(l="Create Render Layers", w=200, cll=True, bgc=(.2,.2,.2))
widgets["CarKey"] = cmds.checkBox(l="Car_Env", v=True)
widgets["CarEnv"] = cmds.checkBox(l="Car_Key", v=True)
widgets["BGKey"] = cmds.checkBox(l="BG_Env", v=True)
widgets["BGEnv"] = cmds.checkBox(l="BG_Key", v=True)
widgets["AO"] = cmds.checkBox(l="All_AO", v=True)
widgets["MatteA"] = cmds.checkBox(l="All_MatteA", v=True)
widgets["MatteB"] = cmds.checkBox(l="All_MatteB", v=True)
widgets["MoVec"] = cmds.checkBox(l="All_MoVec", v=True)
widgets["Shadow"] = cmds.checkBox(l="All_Shadow", v=True)
widgets["createBut"] = cmds.button(l="Create Layers", w=200, h=40, bgc=(.6,.8,.6), c=createRL)
cmds.text("NOTE: this is setting the overrides for \nthe moVec layer RG's and materials \n(if you have them in scene\n for the AO and Movec layers but \n NO passes are set up")
cmds.separator(h=20, style = "double")
#widgets["copyBut"] = cmds.button(l="Copy Selected Layer", w=200, h=40, bgc=(.8,.8,.6), c=copyRL)
#cmds.separator(h=20, style = "double")
widgets["importBut"] = cmds.button(l="Import RL Shaders File", w=200, h=40, bgc=(.8,.6,.6), c=importRL)
cmds.showWindow(widgets["win"])
cmds.window(widgets["win"], e=True, w=200, h=400)
#create render layers