def setWeights(mode, *args): """mode: "zero" to zero all weights or "selection" to apply weights to selection""" #---------------- if current selection is a transform then do the whole thing by this mult value. . . . deformers = cmds.textScrollList(widgets["defTSL"], q=True, selectItem=True) if mode == "selection": c, w = getWeights() if not c or not w: cmds.warning("zbw_deformerWeights(line 85): Couldn't get the components.") return() mult = cmds.floatFieldGrp(widgets["weightFFG"], q=True, v1=True) for d in deformers: for each in zip(c, w): cmds.percent(d, each[0], v=(each[1]*mult)) if mode == "zero": t = cmds.textFieldGrp(widgets["objTFG"], q=True, tx=True) sel = [] if rig.isType(t, "mesh"): sel = cmds.ls("{0}.vtx[*]".format(t), fl=True) elif rig.isType(t, "nurbsCurve") or rig.isType(t, "nurbsSurface"): sel = cmds.ls("{0}.cv[*]".format(t), fl=True) for d in deformers: if sel: for each in sel: cmds.percent(d, each, v=0)
def scale_the_objects(scaleVal, *args): """ does the scaling bits """ sel = cmds.ls(sl=True, type="transform") if sel: for obj in sel: if (rig.isType(obj, "nurbsSurface")) or (rig.isType( obj, "nurbsCurve")): piv = cmds.xform(obj, q=True, ws=True, rp=True) cvs = cmds.select((obj + ".cv[*]")) cmds.scale(scaleVal, scaleVal, scaleVal, cvs, pivot=piv) elif rig.isType(obj, "mesh"): piv = cmds.xform(obj, q=True, ws=True, rp=True) vs = cmds.select((obj + ".vtx[*]")) cmds.scale(scaleVal, scaleVal, scaleVal, vs, pivot=piv) else: cmds.warning( "{0} isn't a nurbs or poly object, so it was skipped". format(obj)) # clear and reselect all if sel: cmds.select(cl=True) cmds.select(sel) return (True) return (False)
def align_attach(*args): """ alings then attaches two selected curves Args: *args: Returns: """ # check selection, curves, etc sel = cmds.ls(sl=True) crv1 = "" crv2 = "" if sel and len(sel)== 2: check1 = rig.isType(sel[0], "nurbsCurve") check2 = rig.isType(sel[1], "nurbsCurve") if not check1 and check2: cmds.warning("you must select two curves!") return else: cmds.warning("you must select two curves!") return crv1, crv2 = sel[0], sel[1] newCrv = cmds.alignCurve(crv1, crv2, ch=False, replaceOriginal=False, attach=True, keepMultipleKnots=True, positionalContinuityType=2, tangentContinuity=False, curvatureContinuity=False, name = "{0}_ATT".format(crv1)) cmds.setAttr("{0}.v".format(crv1), 0) cmds.setAttr("{0}.v".format(crv2), 0)
def camera_check(*args): """ make sure that a camera is in the textfield grp """ cam = cmds.textFieldButtonGrp(widgets["camTFBG"], q=True, tx=True) if rig.isType(cam, "camera"): return (cam) else: return (False)
def curveCVControls(*args): """ puts a controls on each cv of selected curves """ sel = cmds.ls(sl=True, type="transform") for crv in sel: if rig.isType(crv, "nurbsCurve"): curve_CV_controls_execute(crv)
def getWeights(*args): tType = "" t = cmds.textFieldGrp(widgets["objTFG"], q=True, tx=True) if rig.isType(t, "mesh"): tType = "poly" if rig.isType(t, "nurbsCurve") or rig.isType(t, "nurbsSurface"): tType = "nurbs" # get type of object (nurbs or poly) selection = OpenMaya.MSelectionList() softSelection = OpenMaya.MRichSelection() OpenMaya.MGlobal.getRichSelection(softSelection) softSelection.getSelection(selection) dagPath = OpenMaya.MDagPath() component = OpenMaya.MObject() # Filter Defeats the purpose of the else statement # print "********** selection: " + str(OpenMaya.MDagPath(selection)) if tType == "nurbs": iter = OpenMaya.MItSelectionList( selection,OpenMaya.MFn.kCurveCVComponent) elif tType == "poly": iter = OpenMaya.MItSelectionList( selection,OpenMaya.MFn.kMeshVertComponent) else: return(None, None) elements, weights = [], [] while not iter.isDone(): iter.getDagPath( dagPath, component ) dagPath.pop() #Grab the parent of the shape node node = dagPath.fullPathName() fnComp = OpenMaya.MFnSingleIndexedComponent(component) getWeight = lambda i: fnComp.weight(i).influence() if fnComp.hasWeights() else 1.0 for i in range(fnComp.elementCount()): if tType == "nurbs": elements.append('%s.cv[%i]' % (node, fnComp.element(i))) elif tType == "poly": elements.append('%s.vtx[%i]' % (node, fnComp.element(i))) weights.append(getWeight(i)) iter.next() return elements, weights
def populate_camera(*args): """ puts the camera in the text field group for later stuff """ sel = cmds.ls(sl=True) if len(sel) != 1: cmds.warning("need to select 1 object!") return () if rig.isType(sel[0], "camera"): cmds.textFieldButtonGrp(widgets["camTFBG"], e=True, tx=sel[0]) else: cmds.warning("that's not a camera!")
def reverse_curve(*args): sel = cmds.ls(sl=True, exactType = "transform") check = False if sel: for x in sel: check = rig.isType(x, "nurbsCurve") if check: cmds.reverseCurve(x, ch=False, replaceOriginal=True) else: cmds.warning("Must select some curves") return cmds.select(sel, r=True)
def get_curve(*args): sel = cmds.ls(sl=True) crv = "" if sel and len(sel) == 1: check = rig.isType(sel[0], "nurbsCurve") if not check: cmds.warning("Must select one curve object!") return else: cmds.warning("Must select one curve object!") return crv = sel[0] cmds.textFieldButtonGrp(widgets["curveTFBG"], e=True, tx = crv)
def separate_abc(*args): """ seperates abcs into xforms and parents them under the camera and moves them to (appox) image plane location """ cam = camera_check() if not cam: cmds.warning( "need to select your render cam in the window (top of window)") sel = cmds.ls(sl=True) if not sel: cmds.warning("no abc selected!") return () outGeoList = [] for abc in sel: hold = False if rig.isType(abc, "mesh"): shps = [x for x in cmds.listRelatives(abc, s=True)] pos = cmds.xform(abc, ws=True, q=True, rp=True) par = "" parList = cmds.listRelatives(abc, p=True) if parList: if parList[0] != cam: parent_and_zero(sel) par = parList[0] for shp in shps: nShp = cmds.rename(shp, "{0}Shape".format(shp)) xf = cmds.group(em=True, name=shp) cmds.xform(xf, ws=True, t=pos) cmds.parent(nShp, xf, r=True, s=True) if par: cmds.parent(xf, par) cmds.setAttr("{0}.t".format(xf), 0, 0, 0) cmds.setAttr("{0}.r".format(xf), 0, 0, 0) cmds.setAttr("{0}.s".format(xf), 1, 1, 1) cmds.setAttr("{0}.t".format(xf), 0, -5.371, -18.684) outGeoList.append(xf) else: cmds.warning("{0} is not a mesh. Skipping!".format(abc)) hold = True if not hold: cmds.delete(abc) cmds.select(outGeoList)
def rebuild_curves(*args): """ rebuilds selected curves to specs in window """ sel = cmds.ls(sl=True, exactType = "transform") check = False newCrvs = [] if sel: for x in sel: check = rig.isType(x, "nurbsCurve") if check: crv = x parent = "" parList = cmds.listRelatives(crv, parent = True) if parList: parent = parList[0] num = calculate_pts(crv) newCrv = cmds.rebuildCurve(crv, rebuildType = 0, spans = num, keepRange = 0, replaceOriginal=False, name = "{0}_RB".format(crv))[0] newCrvs.append(newCrv) if cmds.objExists("crvRebuildOriginals_GRP"): if (parent and parent != "crvRebuildOriginals_GRP"): cmds.parent(newCrv, parent) if parent != "crvRebuildOriginals_GRP": cmds.parent(crv, "crvRebuildOriginals_GRP") cmds.setAttr("{0}.v".format(crv), 0) else: cmds.group(empty = True, name = "crvRebuildOriginals_GRP") if (parent and parent != "crvRebuildOriginals_GRP"): cmds.parent(newCrv, parent) if parent != "crvRebuildOriginals_GRP": cmds.parent(crv, "crvRebuildOriginals_GRP") cmds.setAttr("{0}.v".format(crv), 0) else: cmds.warning("{0} is not a nurbsCurve object. Skipping!".format(x)) cmds.select(newCrvs, r=True)
def move_pivot(end, *args): """ Args: end (int): parameter value (0 or 1 from buttons) the point on curve will return, start or end *args: """ check = False sel = cmds.ls(sl=True, exactType = "transform") if sel: for x in sel: check = rig.isType(x, "nurbsCurve") if check: # get curve info pos = cmds.pointOnCurve(x, parameter = end, position = True) cmds.xform(x, ws=True, piv=pos) else: cmds.warning("{0} is not a nurbsCurve object. Skipping!".format(x))
def align_along_curve(*args): """ aligns and objet along a curve at given param Args: *args: Returns: void """ sel = cmds.ls(sl=True, type="transform") if len(sel) != 2: cmds.warning("You need to select curve then object to align!") return() crv = sel[0] obj = sel[1] if not rig.isType(crv, "nurbsCurve"): cmds.warning("select curve first, THEN object") return() param = cmds.floatFieldGrp(widgets["alExFFG"], q=True, v1=True) rig.align_to_curve(crv, obj, param)
def reparameter(*args): """ reparameterizes curves to be from 0-1 Args: Returns: """ sel = cmds.ls(sl=True, exactType = "transform") check = False newCrvs = [] if sel: for x in sel: check = rig.isType(x, "nurbsCurve") if check: crv = x newCrv = cmds.rebuildCurve(crv, constructionHistory=False, rebuildType = 0, keepControlPoints=True, keepRange = 0, replaceOriginal=True, name = "{0}_RB".format(crv))[0] # reconnect parents and children of orig curve else: cmds.warning("{0} is not a nurbsCurve object. Skipping!".format(x)) cmds.select(sel, r=True)