def getPlugValue( plug ):

    #if plug.isArray():
    #    raise TypeError, "array plugs of this type are not supported"
    
    obj = plug.attribute()
    apiType = obj.apiType()

    if apiType in [ MFn.kAttribute2Double, MFn.kAttribute2Float, MFn.kAttribute2Short, MFn.kAttribute2Int,
                    MFn.kAttribute3Double, MFn.kAttribute3Float, MFn.kAttribute3Short, MFn.kAttribute3Int,
                    MFn.kAttribute4Double,
                    MFn.kCompoundAttribute ] :
        res = []
        for i in range(plug.numChildren()):
            res.append( getPlugValue( plug.child(i) ) )
        return tuple(res)

    elif apiType in [ MFn.kDoubleLinearAttribute, MFn.kFloatLinearAttribute ] :
        return plug.asMDistance()

    elif apiType in [ MFn.kDoubleAngleAttribute, MFn.kFloatAngleAttribute ] :
        return plug.asMAngle()

    elif apiType == MFn.kTimeAttribute:
        return plug.asMTime()

    elif apiType == MFn.kNumericAttribute:
        #return getNumericPlugValue(plug)
        nAttr = MFnNumericAttribute(obj)
        dataType = nAttr.unitType()
        if dataType == MFnNumericData.kBoolean:
            return plug.asBool()
        
        elif dataType in [ MFnNumericData.kShort, MFnNumericData.kInt, MFnNumericData.kLong, MFnNumericData.kByte] :
            return plug.asInt()
        
        elif dataType in [ MFnNumericData.kFloat, MFnNumericData.kDouble, MFnNumericData.kAddr] :
            return plug.asDouble()
        raise "%s: unknown numeric attribute type: %s" % (plug.partialName(True, True, True, False, True, True), dataType)
    
    elif apiType == MFn.kEnumAttribute:
        return plug.asInt()
    
    elif apiType == MFn.kTypedAttribute:
        tAttr = MFnTypedAttribute( obj )
        dataType = tAttr.attrType()
        
        
        if dataType == MFnData.kInvalid:
            return None
        
        elif dataType == MFnData.kString:
            return plug.asString()
        
        elif dataType == MFnData.kNumeric:
            
            # all of the dynamic mental ray attributes fail here, but i have no idea why they are numeric attrs and not message attrs.
            # cmds.getAttr returns None, so we will too.
            try:
                dataObj = plug.asMObject()
            except:
                return
            
            try:
                numFn = MFnNumericData( dataObj )
            except RuntimeError:
                if plug.isArray():
                    raise TypeError, "%s: numeric arrays are not supported" % plug.partialName(True, True, True, False, True, True)
                else:
                    raise TypeError, "%s: attribute type is numeric, but its data cannot be interpreted numerically" % plug.partialName(True, True, True, False, True, True)
            dataType = numFn.numericType()
                    
            if dataType == MFnNumericData.kBoolean:
                return plug.asBool()
            
            elif dataType in [ MFnNumericData.kShort, MFnNumericData.kInt, MFnNumericData.kLong, MFnNumericData.kByte] :
                return plug.asInt()
            
            elif dataType in [ MFnNumericData.kFloat, MFnNumericData.kDouble, MFnNumericData.kAddr] :
                return plug.asDouble()
            
            elif dataType == MFnNumericData.k2Short :
                ptr1 = SafeApiPtr('short')
                ptr2 = SafeApiPtr('short')
                
                numFn.getData2Short(ptr1(),ptr2())
                return ( ptr1.get(), ptr2.get() )
            
            elif dataType in [ MFnNumericData.k2Int, MFnNumericData.k2Long ]:
                ptr1 = SafeApiPtr('int')
                ptr2 = SafeApiPtr('int')
                
                numFn.getData2Int(ptr1(), ptr2())
                return ( ptr1.get(), ptr2.get() )
        
            elif dataType == MFnNumericData.k2Float :
                ptr1 = SafeApiPtr('float')
                ptr2 = SafeApiPtr('float')
                
                numFn.getData2Float(ptr1(), ptr2())
                return ( ptr1.get(), ptr2.get() )
             
            elif dataType == MFnNumericData.k2Double :
                ptr1 = SafeApiPtr('double')
                ptr2 = SafeApiPtr('double')
                
                numFn.getData2Double(ptr1(), ptr2())
                return ( ptr1.get(), ptr2.get() )
        
            elif dataType == MFnNumericData.k3Float:
                ptr1 = SafeApiPtr('float')
                ptr2 = SafeApiPtr('float')
                ptr3 = SafeApiPtr('float')
                 
                numFn.getData3Float(ptr1(), ptr2(), ptr3())
                return ( ptr1.get(), ptr2.get(), ptr3.get() )
            
            elif dataType ==  MFnNumericData.k3Double:
                ptr1 = SafeApiPtr('double')
                ptr2 = SafeApiPtr('double')
                ptr3 = SafeApiPtr('double')
                
                numFn.getData3Double(ptr1(), ptr2(), ptr3())
                return ( ptr1.get(), ptr2.get(), ptr3.get() )
            
            elif dataType == MFnNumericData.kChar :
                return plug.asChar()
            
            raise TypeError, "%s: Unsupported numeric attribute: %s" % (plug.partialName(True, True, True, False, True, True),dataType)
        
        elif dataType == MFnData.kMatrix :
            return MFnMatrixData( plug.asMObject() ).matrix()
        
        elif dataType == MFnData.kDoubleArray :
            try:
                dataObj = plug.asMObject()
            except RuntimeError:
                return []
            return MFnDoubleArrayData( dataObj ).array()
        
        elif dataType == MFnData.kIntArray :
            try:
                dataObj = plug.asMObject()
            except RuntimeError:
                return []
            return MFnIntArrayData( dataObj ).array()
        
        elif dataType == MFnData.kPointArray :
            try:
                dataObj = plug.asMObject()
            except RuntimeError:
                return []
            return MFnPointArrayData( dataObj ).array()
        
        elif dataType == MFnData.kVectorArray :
            try:
                dataObj = plug.asMObject()
            except RuntimeError:
                return []
            return MFnVectorArrayData( dataObj ).array()
        
        elif dataType == MFnData.kStringArray :
            try:
                dataObj = plug.asMObject()
            except RuntimeError:
                return []
            return MFnStringArrayData( dataObj ).array()
        raise TypeError, "%s: Unsupported typed attribute: %s" % (plug.partialName(True, True, True, False, True, True),dataType)
    
    raise TypeError, "%s: Unsupported Type: %s" % (plug.partialName(True, True, True, False, True, True), obj.apiTypeStr())
given an MPlug, get its value
dataset/ETHPy150Open CountZer0/PipelineConstructionSet/python/maya/site-packages/pymel-1.0.3/pymel/api/allapi.py/getPlugValue