我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用maya.cmds.text()。
def randomSelectionUI(*args): if cmds.window("win", exists = True): cmds.deleteUI("win") widgets["win"] = cmds.window("win", w=280, h=75, t="zbw_randomSelection") widgets["mainCLO"] = cmds.columnLayout() widgets["text"] = cmds.text("What percent of selection do you want to keep?") widgets["keepIFG"] = cmds.intFieldGrp(l=" % to keep:", v1=50, h=40, cw = ([1, 65], [2, 50]), cal = ([1,"left"], [2, "left"])) widgets["text2"] = cmds.text("Random: each obj has % chance to be removed") widgets["text3"] = cmds.text("Precise: exact num removed, but randomly chosen") cmds.separator(h=10) widgets["typeRBG"] = cmds.radioButtonGrp(l="Type:", l1 = "Random Remove", l2 = "Precise Remove", nrb = 2, sl = 1, cw = ([1, 30], [2,120], [3, 120], [4, 50]), cal = ([1, "left"], [2,"left"], [3, "left"], [4, "left"])) widgets["but"] = cmds.button(l="Reselect", w=280, h=40, bgc = (.6, .8, .6), c = doSel) cmds.window(widgets["win"], e=True, w=280, h=75) cmds.showWindow(widgets["win"])
def _create_ui(self): u"""UI???""" safe_delete_window(self._WINDOW_NAME) win = cmds.window(self._WINDOW_NAME, t="Convert Color Code", mb=True, w=480, h=128) cmds.menu(l="Option") cmds.menuItem(l="ColorEditor", c=self.get_color_from_editor) cmds.columnLayout(adj=True, rs=2) self.color_code_field = cmds.textFieldButtonGrp(l="Color code", bl="Convert", bc=self._convert) self.decimal_point_field = cmds.intFieldGrp(l="Decimal point", nf=1, v1=2) self.result_field = cmds.textFieldGrp(l="Result") cmds.setParent("..") cmds.columnLayout(adj=True) self.color_preview = cmds.text(l="", h=24) cmds.setParent("..") cmds.showWindow(win)
def _convert(self, *args): u"""?????????""" code = cmds.textFieldButtonGrp(self.color_code_field, q=True, tx=True) if len(code) == 7 and code.startswith("#"): code = code[1:] if len(code) != 6: return try: int(code, 16) except ValueError, e: print(e) return decimal_point = cmds.intFieldGrp(self.decimal_point_field, q=True, v1=True) r = round(int(code[0:2], 16) / 255, decimal_point) g = round(int(code[2:4], 16) / 255, decimal_point) b = round(int(code[4:6], 16) / 255, decimal_point) bgc = self._COLOR_FORMAT.format(str(r), str(g), str(b)) cmds.textFieldGrp(self.result_field, e=True, tx=bgc) cmds.text(self.color_preview, e=True, bgc=[r, g, b])
def findScriptUI(*args): if cmds.window("findScript", exists = True): cmds.deleteUI("findScript") widgets["win"] = cmds.window("findScript", t="zbw_findPath", w=300, h=200) widgets["mainCLO"] = cmds.columnLayout() cmds.separator(h=10) widgets["textTx"] = cmds.text(l="Will search your active python paths. \nNo need for suffix (.py or .mel)\nNo wildcards(*). Just string, 3 chars min", al="left") cmds.separator(h=20) widgets["nameTFG"] = cmds.textFieldGrp(l="search for:", cw = [(1, 75), (2,200)], cal = [(1, "left"),(2, "right")]) cmds.separator(h=20) widgets["searchBut"] = cmds.button(l="Search python paths!", w=300, h=50, bgc=(0,.6, 0), c=searchPaths) cmds.separator(h=20) widgets["resultTxt"] = cmds.textFieldGrp(l="results:", ed=False, w=300, cw = [(1, 75), (2,200)], bgc = (0,0,0) , cal = [(1, "left"),(2, "right")]) cmds.showWindow(widgets["win"])
def snapUI(): """simple snap UI for snapping""" if cmds.window("snapWin", exists=True): cmds.deleteUI("snapWin", window=True) cmds.windowPref("snapWin", remove=True) widgets["win"] = cmds.window("snapWin", t="zbw_snap", w=210, h=100, rtf=True) widgets["mainCLO"] = cmds.columnLayout(w=210, h=100) cmds.text("Select the target object(s),\nthen the object(s) you want to snap", al="center", w=210) cmds.separator(h=5, style="single") widgets["cbg"] = cmds.checkBoxGrp(l="Options: ", ncb=2, v1=1, v2=1, l1="Translate", l2="Rotate", cal=[(1,"left"),(2,"left"), (3,"left")], cw=[(1,50),(2,75),(3,75)]) widgets["avgRBG"] = cmds.radioButtonGrp(nrb=2, l1="Snap all to first", l2="Snap last to avg", cal=[(1,"left"),(2,"left"),(3,"left")], cw=[(1,100),(2,100)],sl=1) widgets["rpCB"] = cmds.checkBox(l="Use Rotate Pivot To Query Position?", v=1) widgets["snapPivCB"] = cmds.checkBox(l="Snap via pivot? (vs. translate value)", v=1) cmds.separator(h=5, style="single") widgets["snapButton"] = cmds.button(l="Snap obj(s)!", w=210, h=40, bgc=(.6,.8,.6), c=partial(snapIt, False)) widgets["snapPivButton"] = cmds.button(l="Snap pivot!", w=210, h=20, bgc=(.8,.6,.6), c=partial(snapIt, True)) cmds.window(widgets["win"], e=True, w=5, h=5) cmds.showWindow(widgets["win"])
def zbw_mmAddMObjs(*args): """ adds textFields to the UI for adding target objects for the message attrs """ #delete text confirm dialogue if it exists zbw_mmDeleteConfirm() #figure out what objects are already parented children = cmds.rowColumnLayout("mmRCLayout" , q=True, ca=True) #figure out where stuff goes (2 column layout, so divide by 2), 1 based if children: currentNum = len(children)/2 + 1 currentTFG = "attr" + str(currentNum) currentTFBG = "obj" + str(currentNum) #if no objects exist . . . else: currentTFG = "attr1" currentTFBG = "obj1" cmds.textFieldGrp(currentTFG, l="addedAttr (ln)", cal=(1, "left"), cw2=(100, 150), p="mmRCLayout") cmds.textFieldButtonGrp(currentTFBG, l="messageObj", cal=(1, "left"), cw3=(75,150,50), p="mmRCLayout", bl="get", bc=partial(zbw_mmAddTarget, currentTFBG)) #proc to grab the attrs and create connections
def zbw_mmChangeConnectAttrUI(base, attr, obj, *args): if (cmds.window('zbw_mmChangeAttrUI', exists=True)): cmds.deleteUI('zbw_mmChangeAttrUI', window=True) cmds.windowPref('zbw_mmChangeAttrUI', remove=True) window=cmds.window('zbw_mmChangeAttrUI', widthHeight=(400,80), title='zbw_messageMapper_changeAttrName') cmds.columnLayout() #show old attr name cmds.text("old attribute name: " + attr) #asks for the new attr name cmds.textFieldGrp("zbw_mmChangeAttrTFG", l="new attr name (just attr name)") #button to do it (pass along attr, obj) cmds.button("zbw_mmChangeAttrB", l="change attr!", c=partial(zbw_mmChangeConnectAttr, base, attr, obj)) cmds.showWindow(window) #force window to size cmds.window('zbw_mmChangeAttrUI', e=True, widthHeight = (400,80)) pass
def zbw_mmChangeConnectObjUI(base, attr, obj, *args): if (cmds.window('zbw_mmChangeObjUI', exists=True)): cmds.deleteUI('zbw_mmChangeObjUI', window=True) cmds.windowPref('zbw_mmChangeObjUI', remove=True) window=cmds.window('zbw_mmChangeObjUI', widthHeight=(400,85), title='zbw_messageMapper_changeObjName') cmds.columnLayout() #show old attr name cmds.text("base attribute name: " + attr) cmds.text("old connected obj name: " + obj) #asks for the new attr name cmds.textFieldButtonGrp("zbw_mmChangeObjTFBG", l="select new obj: ", bl="get", bc=partial(zbw_mmAddTarget, "zbw_mmChangeObjTFBG")) #button to do it (pass along attr, obj) cmds.button("zbw_mmChangeObjB", l="change obj!", c=partial(zbw_mmChangeConnectObj, base, attr, obj)) cmds.showWindow(window) #force window to size cmds.window('zbw_mmChangeObjUI', e=True, widthHeight = (420,85))
def modelSequenceUI(*args): if (cmds.window("modSeq", exists=True)): cmds.deleteUI("modSeq") widgets["win"] = cmds.window("modSeq", w = 300, h = 220, t = "zbw_modelSequence") widgets["mainCLO"] = cmds.columnLayout(w = 300,h = 220) cmds.separator(h=10) cmds.text("Select ONE object to be duplicated \nThis will duplicate it for frames selected and group", al="left") cmds.separator(h=20) #textFieldGRP - name of objs widgets["sufTFG"] = cmds.textFieldGrp(l="Sequence Suffix:", cw = [(1, 100), (2,200)], cal = [(1, "left"),(2, "right")]) #radioButtonGrp - timeslider or frame range widgets["frmRBG"] = cmds.radioButtonGrp(l="Get Frames From:", nrb=2, sl=2, l1="Time Slider", l2="Frame Range", cw = [(1, 120), (2,80), (3,80)], cal = [(1, "left"),(2, "left")], cc=enableFR) #textFieldGrp - framerange (enable) widgets["frmRngIFG"] = cmds.intFieldGrp(l="Range:", nf=2, en=True, v1=0, v2 = 9, cw = [(1, 120), (2,80), (3,80)], cal = [(1, "left"),(2, "left")]) #int = by frame step widgets["stepIFG"] = cmds.intFieldGrp(l="Step By (frames):", v1 = 1, cw = [(1, 120), (2,80)], cal = [(1, "left"),(2, "right")]) cmds.separator(h=30) widgets["doBut"] = cmds.button(l="Create duplicates of objects!", w= 300, h=40, bgc = (0,.8, 0), c=getValues) cmds.showWindow(widgets["win"])
def dupeSwapUI(): """UI for script""" if cmds.window("dupeWin", exists=True): cmds.deleteUI("dupeWin") cmds.window("dupeWin", t="zbw_dupeSwap", w=250, h=100) cmds.columnLayout("dupeCLO") cmds.text("Select the initial object. then select the", al="center", w=250) cmds.text("duplicates and press button", al="center", w=250) cmds.separator(h=5, style ="single") cmds.radioButtonGrp("inputsRBG", l="inputs:", nrb=3, l1="none", l2="connect", l3="duplicate", cw=[(1, 50), (2,47), (3,63), (4,40)], cal=[(1,"left"), (2,"left"), (3,"left"), (4,"left")], sl=1) cmds.separator(h=5, style ="single") cmds.button("dupeButton", l="Swap Elements", w=250, h=50, bgc=(.6, .8,.6), c=dupeIt) cmds.showWindow("dupeWin") cmds.window("dupeWin", e=True, w=250, h=100)
def connectShapeVis(*args): """Connects the attr from the assoc. text field to the shape Visibility of selected objects""" sel = cmds.ls(sl=True, type="transform") driver = cmds.textFieldButtonGrp(widgets["toShapeVis"], q=True, tx=True) if sel: if driver: for obj in sel: shapes = cmds.listRelatives(obj, s=True) for shape in shapes: try: cmds.connectAttr(driver, "%s.v" % shape, f=True) cmds.warning("Connected %s to %s" % (driver, shape)) except: cmds.warning("Couldn't connect %s to %s. Sorry! Check the Script Editor." % (driver, shape)) else: cmds.warning("You need to select an object to connect the shape.vis!")
def ui(): ''' User interface for stopwatch ''' with utl.MlUi('ml_stopwatch', 'Stopwatch', width=400, height=175, info='''Press the start button to start recording. Continue pressing to set marks. When finished, press the stop button and the report will pop up.''') as win: mc.checkBoxGrp('ml_stopwatch_round_checkBox',label='Round to nearest frame', value1=True, annotation='Only whole number frames') mc.text('ml_stopwatch_countdown_text', label='Ready...') mc.button('ml_stopwatch_main_button', label='Start', height=80) _setButtonStart() mc.button(label='Stop', command=_stopButton, annotation='Stop the recording.')
def about(self, *args): ''' This pops up a window which shows the revision number of the current script. ''' text='by Morgan Loomis\n\n' try: __import__(self.module) module = sys.modules[self.module] text = text+'Revision: '+str(module.__revision__)+'\n' except StandardError: pass try: text = text+'ml_utilities Rev: '+str(__revision__)+'\n' except StandardError: pass mc.confirmDialog(title=self.name, message=text, button='Close')
def _populateSelectionField(self, channel, field, *args): selectedChannels = None if channel: selectedChannels = getSelectedChannels() if not selectedChannels: raise RuntimeError('Please select an attribute in the channelBox.') if len(selectedChannels) > 1: raise RuntimeError('Please select only one attribute.') sel = mc.ls(sl=True) if not sel: raise RuntimeError('Please select a node.') if len(sel) > 1: raise RuntimeError('Please select only one node.') selection = sel[0] if selectedChannels: selection = selection+'.'+selectedChannels[0] mc.textFieldButtonGrp(field, edit=True, text=selection)
def colorControlLayout(self, label=''): mc.rowLayout( numberOfColumns=4, columnWidth4=(150, 200, 90, 80), adjustableColumn=2, columnAlign=(1, 'right'), columnAttach=[(1, 'both', 0), (2, 'both', 0), (3, 'both', 0), (4, 'both', 0)] ) mc.text(label=label) colorSlider = mc.colorSliderGrp( label='', adj=2, columnWidth=((1,1),(3,1))) mc.button(label='From Selected', ann='Get the color of the selected object.', command=partial(self.setFromSelected, colorSlider)) mc.button(label='Randomize', ann='Set a random color.', command=partial(self.randomizeColors, colorSlider)) controls = mc.layout(colorSlider, query=True, childArray=True) mc.setParent('..') return colorSlider
def quickBreakDownUI(): winName = 'ml_quickBreakdownWin' if mc.window(winName, exists=True): mc.deleteUI(winName) mc.window(winName, title='ml :: QBD', iconName='Quick Breakdown', width=100, height=500) mc.columnLayout(adj=True) mc.paneLayout(configuration='vertical2', separatorThickness=1) mc.text('<<') mc.text('>>') mc.setParent('..') for v in (10,20,50,80,90,100,110,120,150): mc.paneLayout(configuration='vertical2',separatorThickness=1) mc.button(label=str(v)+' %', command=partial(weightPrevious,v/100.0)) mc.button(label=str(v)+' %', command=partial(weightNext,v/100.0)) mc.setParent('..') mc.showWindow(winName) mc.window(winName, edit=True, width=100, height=250)
def update_time(): ''' update the clock display. This will be called once very second by the repeat task. It does need to yield at the end to allow time-slicing, however ''' now = datetime.datetime.now().time() time_string = now.strftime("%-I:%M %S %p") hours, seconds, ampm = time_string.split() hour_style = "font-size:64px; font-family: Impact; color: #8A0F21" sec_style = "font-size:18px; font-family:Arial Black; color: #8A0F21" am_style = "font-size:24px; font-family:Arial Black; font-weight:900; color: #700D21" def set_control (ctl, value, style): def make_text(text, style): return '<span style="{0}">{1}</span>'.format(style, text) cmds.text(ctl, e=True, label = make_text(value, style)) set_control(hour, hours, hour_style) set_control(secs, seconds, sec_style) set_control(am, ampm, am_style) yield # set up the update job to repeat every second
def buildUI(self): # To start with we create a layout to hold our UI objects # A layout is a UI object that lays out its children, in this case in a column column = cmds.columnLayout() # Now we create a text label to tell a user how to use our UI cmds.text(label="Use this slider to set the tween amount") # We want to put our slider and a button side by side. This is not possible in a columnLayout, so we use a row row = cmds.rowLayout(numberOfColumns=2) # We create a slider, set its minimum, maximum and default value. # The changeCommand needs to be given a function to call, so we give it our tween function # We need to hold on to our slider's name so we can edit it later, so we hold it in a variable self.slider = cmds.floatSlider(min=0, max=100, value=50, step=1, changeCommand=tween) # Now we make a button to reset our UI, and it calls our reset method cmds.button(label="Reset", command=self.reset) # Finally we don't want to add anymore to our row layout but want to add it to our column again # So we must change the active parent layout cmds.setParent(column) # We add a button to close our UI cmds.button(label="Close", command=self.close) # *args will be a new concept for you # It basically means I do not know how many arguments I will get, so please put them all inside this one list (tuple) called args
def buildUI(self): column = cmds.columnLayout() cmds.text(label="Use this slider to set the tween amount") cmds.rowLayout(numberOfColumns=2) self.slider = cmds.floatSlider(min=0, max=100, value=50, step=1, changeCommand=tweener.tween) cmds.button(label="Reset", command=self.reset) cmds.setParent(column) cmds.button(label="Close", command=self.close) # And again, we just need to override the reset method # We don't need to define the close, or show methods because it gets those from BaseWindow
def buildUI(self): column = cmds.columnLayout() cmds.text(label="Use the slider to modify the number of teeth the gear will have") cmds.rowLayout(numberOfColumns=4) # This label will show the number of teeth we've set self.label = cmds.text(label="10") # Unlike the tweener, we use an integer slider and we set it to run the modifyGear method as it is dragged self.slider = cmds.intSlider(min=5, max=30, value=10, step=1, dragCommand=self.modifyGear) cmds.button(label="Make Gear", command=self.makeGear) cmds.button(label="Reset", command=self.reset) cmds.setParent(column) cmds.button(label="Close", command=self.close)
def modifyGear(self, teeth): # When the slider is changes, this method will be called. # First we will update the label that displays the number of teeth # the str() function converts the number into a string cmds.text(self.label, edit=True, label=str(teeth)) # If there is a gear already made, then we will set the slider to edit it if self.gear: self.gear.changeTeeth(teeth=teeth)
def reset(self, *args): # When we reset, we will intentionally say we're done with this gear, move on to the next one # So moving the slider now will not adjust an existing gear self.gear = None # We will reset the slider value cmds.intSlider(self.slider, edit=True, value=10) # And finally reset the label value # the str() function converts the number into a string cmds.text(self.label, edit=True, label=str(10))
def printDebug(text): if g_debugMessages is True: print(text)
def printMessage(text): mel.eval("print \"[NR]: {}\\n\"".format(text))
def show_ui(self): u"""Window???""" if cmds.window(self._WINDOW_NAME, exists=True): cmds.deleteUI(self._WINDOW_NAME) self.window = cmds.window(self._WINDOW_NAME, t=self._WINDOW_TITLE, width=340, maximizeButton=False, minimizeButton=False) form = cmds.formLayout() field_group = cmds.columnLayout(adj=True, cal="center", rs=self._MARGIN) cmds.text(u"""??????????????????????????????? ????????????????????????????""", al="left") self.text_scroll = cmds.textScrollList(append=self.get_windows(), ams=False, dcc=self.check_execute) self.text_field = cmds.textFieldGrp(l=u"????", ad2=2, cl2=["left", "left"], cw=[1, 60]) cmds.setParent("..") button_group = cmds.columnLayout(adj=True, cal="center") cmds.button(l="Check", c=self.check_execute) cmds.setParent("..") cmds.formLayout(form, e=True, attachForm=[(field_group, "top", self._MARGIN), (field_group, "left", self._MARGIN), (field_group, "right", self._MARGIN), (button_group, "bottom", self._MARGIN), (button_group, "left", self._MARGIN), (button_group, "right", self._MARGIN)], attachControl=[(button_group, "top", self._MARGIN, field_group)]) cmds.setParent("..") cmds.showWindow(self.window)
def _create_ui(self): safe_delete_window(self._WINDOW_NAME) win = cmds.window(self._WINDOW_NAME) form = cmds.formLayout() field_group = cmds.columnLayout(adj=True, cal="center", rs=self._MARGIN) cmds.text(u"????????focalLength?????Unity?FOV?????????????", al="left") self.text_scroll = cmds.textScrollList(append=self._get_cameras(), ams=False, dcc=self._select) self.text_field = cmds.textFieldGrp(l=u"FOV", ad2=2, cl2=["left", "left"], cw=[1, 60]) self.result_field = cmds.textFieldGrp(l=u"Result", ad2=2, cl2=["left", "left"], cw=[1, 60]) cmds.setParent("..") button_group = cmds.columnLayout(adj=True, cal="center") cmds.button(l="Apply", c=self._apply) cmds.setParent("..") cmds.formLayout(form, e=True, attachForm=[(field_group, "top", self._MARGIN), (field_group, "left", self._MARGIN), (field_group, "right", self._MARGIN), (button_group, "bottom", self._MARGIN), (button_group, "left", self._MARGIN), (button_group, "right", self._MARGIN)], attachControl=[(button_group, "top", self._MARGIN, field_group)]) cmds.setParent("..") cmds.showWindow(win)
def get_color_from_editor(self, *args): u"""colorEditor??????""" res = cmds.colorEditor() if "1" != res.split()[3]: return result = cmds.colorEditor(query=True, rgb=True) decimal_point = cmds.intFieldGrp(self.decimal_point_field, q=True, v1=True) r = round(result[0], decimal_point) g = round(result[1], decimal_point) b = round(result[2], decimal_point) bgc = self._COLOR_FORMAT.format(str(r), str(g), str(b)) cmds.textFieldGrp(self.result_field, e=True, tx=bgc) cmds.text(self.color_preview, e=True, bgc=[r, g, b])
def clearAll(self, *args): """clears all the fields""" fieldNames = ["origTxFFG", "origTyFFG", "origTzFFG", "origSxFFG", "origSyFFG", "origSzFFG", "origRxFFG", "origRyFFG", "origRzFFG", "modTxFFG", "modTyFFG", "modTzFFG", "modRxFFG", "modRyFFG", "modRzFFG", "modSxFFG", "modSyFFG", "modSzFFG", "difTxFFG", "difTyFFG", "difTzFFG", "difRxFFG", "difRyFFG", "difRzFFG", "difSxFFG", "difSyFFG", "difSzFFG"] cmds.textFieldGrp(self.widgets["baseTFG"], e=True, tx="") for field in fieldNames: cmds.floatFieldGrp(self.widgets[field], e=True, v1=0) cmds.floatFieldGrp(self.widgets["baseFrameFFG"], e=True, v1=0) cmds.text(self.widgets["doneText"], e=True, l="No Status/All Cleared. Select a base object!", bgc=(.5,.5,.5)) # def restoreBase(self, *args): # """restores the base obj to the text field""" # cmds.textFieldGrp(self.widgets["baseTFG"], e=True, tx=self.baseObj) # cmds.floatFieldGrp(self.widgets["baseFrameFFG"], e=True, v1=self.frame)
def commonUI(self): ######### modify for inheritence ########### cmds.text('this is where the common UI elements go') cmds.separator(h=100) pass
def customUI(self): ######### modify for inheritence ########### cmds.text("this is where the custom UI elements go") cmds.separator(h=200) pass
def clearAll(layout, *args): """clears the selected text scroll list""" cmds.textScrollList(widgets[layout], e=True, ra=True)
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