def copyBitSettings(): ''' Copies the bit shape settings (OpenGL stuff) from the second object to the first (in selection order). ''' selList = cmds.ls( selection=True, long=True ) depFn = OpenMaya.MFnDependencyNode() if len(selList) == 2: # First object is target. targetShape = cmds.listRelatives( selList[0], shapes=True, fullPath=True )[0] targetShapeMObj = NodeUtility.getDependNode( targetShape ) depFn.setObject( targetShapeMObj ) targetShapeType = depFn.typeName() # Second object is source. sourceShape = cmds.listRelatives( selList[1], shapes=True, fullPath=True )[0] sourceShapeMObj = NodeUtility.getDependNode( sourceShape ) depFn.setObject( sourceShapeMObj ) sourceShapeType = depFn.typeName() if targetShapeType == sourceShapeType: # The types match. Do the copy of attribute settings. for attr in cmds.listAttr( sourceShape, multi=True, keyable=True ): # Get the plugs. sourcePlug = NodeUtility.getPlug( sourceShape, attr ) targetPlug = NodeUtility.getPlug( targetShape, attr ) # Get the source plug value. sourcePlugValue = NodeUtility.getPlugValue( sourcePlug ) # Set the target's plug value. NodeUtility.setPlugValue( targetPlug, sourcePlugValue ) else: raise ValueError( '{0} and {1} do not match.'.format( selList[0], selList[1] ) )
def createCompoundCurve(inCurves): """ Merges all the controls into one transform node. @param inCurves: List of Strings. Names of curves to combine under one transform node. The first curve in the list is considered the parent of all the others. @return: MObject. Compound curve transform node. """ # List for creating the compound. compoundList = [] # Get the nurbs curves of all curves in the list. for index in range(1, len(inCurves)): curve = NodeUtility.getDagPath(inCurves[index]) for child in xrange(curve.childCount()): nurb = curve.child(child) nurbDagPath = OpenMaya.MDagPath.getAPathTo(nurb) if nurb.apiType() == OpenMaya.MFn.kNurbsCurve: compoundList.append(nurbDagPath.fullPathName()) # Add the transform of the parent curve. This is the first curve passed into # the function. parent = NodeUtility.getDagPath(inCurves[0]) compoundList.append(parent.fullPathName()) # Now parent the shapes to the first curve's transform node. cmds.parent(compoundList, shape=True, relative=True) # Delete the remaining transform nodes of the other curves. for index in range(1, len(inCurves)): cmds.delete(inCurves[index]) # Returns a MObject. return NodeUtility.getDependNode(parent.fullPathName())
def addPlug( inBit, inPlugName, inAttrType, inAttrDataType ): ''' Adds a plug to the frame bit. @param inBit: String. Name of the bit to add the attribute to. @param inPlugName: String. Name of the plug to add. @param inAttrType: String. Type of attribute to add. @param inAttrDataType: String. The attribute data type. ''' if inAttrType == 'attributeType': if inAttrDataType == 'float3': cmds.addAttr( inBit, longName=inPlugName, attributeType=inAttrDataType ) cmds.addAttr( longName='{0}X'.format( inPlugName ), attributeType='float', parent=inPlugName ) cmds.addAttr( longName='{0}Y'.format( inPlugName ), attributeType='float', parent=inPlugName ) cmds.addAttr( longName='{0}Z'.format( inPlugName ), attributeType='float', parent=inPlugName ) else: cmds.addAttr( inBit, longName=inPlugName, attributeType=inAttrDataType ) elif inAttrType == 'dataType': if inAttrDataType == 'typed': # Make it a string. inAttrDataType = 'string' cmds.addAttr( inBit, longName=inPlugName, dataType=inAttrDataType ) elif inAttrType == 'matrixType': mObj = NodeUtility.getDependNode( inBit ) dgModifier = OpenMaya.MDGModifier() mAttr = OpenMaya.MFnMatrixAttribute() controlMatrix = mAttr.create( inPlugName, inPlugName, OpenMaya.MFnMatrixAttribute.kDouble ) dgModifier.addAttribute( mObj, controlMatrix ) dgModifier.doIt()
def createCurveCircle(inName, inNormal=[0, 1, 0], inRadius=1): """ @param inName: String. Name of curve circle. @param inNormal: List. Direction the curve faces. @param inRadius: Int. Radius of the circle. @return. MObject. Curve circle. """ node = cmds.circle(name=inName, normal=inNormal, radius=inRadius) return NodeUtility.getDependNode(node[0])