#===============================================================================
# author: yangjie
# mobilePhone:15850792203
# QQ:691633493
# E-mail:691633493@
#===============================================================================
from maya.cmds import*
import maya.mel as yjm
import os
def YJ_weighiTool():
    if(window('YJWeightWin',q=1,ex=1)):
    	deleteUI('YJWeightWin',window=1)
    window('YJWeightWin',rtf=1,menuBar=1,s=1,t='YJ_WeightTool_V13.05')
    menu(l='File')
    menuItem(l='Save',c='YJSaveWeight()')
    menuItem(l='Load',c='YJLoadWeightVar()')
    
    ########The main columnLayout that include the pointWeight and painWeight
    columnLayout('MainCL')

    rowLayout('MainRL',numberOfColumns=2,adjustableColumn=True,p='MainCL')
    iconTextButton(p='MainRL',st='iconOnly',l='Paint',i='paintSkinWeights.xpm',w=65,h=30,c='YJ_Change_Mode(1,0)')
    iconTextButton(p='MainRL',st='iconOnly',l='Vertex',i='polyMergeVertex.xpm',w=65,h=30,c='YJ_Change_Mode(0,1)')
    

    ######  the main paintWeightLayout
    columnLayout('DefultWeightCL',p='MainCL',en=0)
    separator(p='DefultWeightCL',style="none",h=5)
    

    ####   the rowLayout for the paintStyle	
    rowLayout('PaintStyle_RL',nc=3,cw3=(50,50,50),p='DefultWeightCL')
    symbolCheckBox('gaussianptBrush',w=34,h=34,onc='YJ_changeBrushType(1)',image='circleGaus.xpm')
    symbolCheckBox('polyBrush',w=34,h=34,onc='YJ_changeBrushType(2)',image='circlePoly.xpm')
    symbolCheckBox('solidptBrush',w=34,h=34,v=1,onc='YJ_changeBrushType(3)',image='circleSolid.xpm')
   
    ####  the sort type of joints rowLayout
    separator(p='DefultWeightCL',style="none",h=5)
    rowLayout('SortType_RL',p='DefultWeightCL',nc=4,cw4=(60,50,50,50))
    text(l='Sort Type:')
    radioCollection('sortType_RC',p='SortType_RL')
    radioButton(l='H',p='SortType_RL',onc='YJArrayTheJntList(2)')
    radioButton(l='N',p='SortType_RL',onc='YJArrayTheJntList(0)')
    radioButton(l='L',p='SortType_RL',onc='YJArrayTheJntList(1)',sl=1)
    
  
    #### the columnLayout for the Joints to show
    separator(p='DefultWeightCL',style="none",h=10)
    columnLayout('JntShowCL',p='DefultWeightCL')
    textScrollList('JTshow_list',ams=1,pma=1,p='JntShowCL',w=210,h=300,sc='changePaintJoint()')
    popupMenu( parent='JTshow_list')
    menuItem(l='Lock',c='YJHoldSelJnt("JTshow_list")')
    menuItem(l='UnLock',c='YJUnHoldSelJnt("JTshow_list")')
    menuItem(l='LockAll',c='YJLockUnlock(1,"JTshow_list")')
    menuItem(l='UnLockAll',c='YJLockUnlock(0,"JTshow_list")')


    
    #### the paintOperation Layout
    separator(p='DefultWeightCL',style="none",h=10)
    rowLayout('PaintOperation_RL',nc=3,cw3=(70,70,70),p='DefultWeightCL')
    
    ###
    columnLayout('PaintOperationCL1',p='PaintOperation_RL')
    text(l='Paint   \n   Operation:')
    ###
    columnLayout('PaintOperationCL2',p='PaintOperation_RL')
    radioCollection('PaintOperation',p='PaintOperationCL2')
    radioButton('absolute',p='PaintOperationCL2',l='Replace',sl=1,onc='YJ_changePaintBrushOperation()')
    radioButton('scale',p='PaintOperationCL2',l='Scale',onc='YJ_changePaintBrushOperation( )')
    ###
    columnLayout('PaintOperationCL3',p='PaintOperation_RL')
    radioButton('additive',p='PaintOperationCL3',l='Add',onc='YJ_changePaintBrushOperation()')
    radioButton('smooth',p='PaintOperationCL3',l='Smooth',onc='YJ_changePaintBrushOperation()')
    
    ####
    separator(p='DefultWeightCL',style="none",h=10)
    rowLayout('paintOperationValue_RL',p='DefultWeightCL',nc=7,
    cw=[(1,30),(2,30),(3,30),(4,30),(5,30),(6,30),(7,30)],
    cal=[(1,'center'),(2,'center'),(3,'center'),(4,'center'),(5,'center'),(6,'center'),(7,'center')])
    button(l='-',w=25,c='YJ_setPaintValueT(0)')
    button(l='.02',w=25,c='YJ_setPaintValueT(0.02)')
    button(l='.1',w=25,c='YJ_setPaintValueT(0.1)')
    button(l='.25',w=25,c='YJ_setPaintValueT(0.25)')
    button(l='.5',w=25,c='YJ_setPaintValueT(0.5)')
    button(l='.75',w=25,c='YJ_setPaintValueT(0.75)')
    button(l='+',w=25,c='YJ_setPaintValueT(1)')
    
    ####
    separator(p='DefultWeightCL',style="none",h=10)
    columnLayout('ValueSlider_CL',p='DefultWeightCL')
    floatSliderGrp('PaintValue',p='ValueSlider_CL',l='Value:',field=1,cw3=(40,40,130),ct3=     ('left','both','both'),min=0.0,max=1.0,cc='YJ_setPaintValue()',
    pre=3,v=0.02)

    ####
    separator(p='DefultWeightCL',style="none",h=10)
    columnLayout('FloodAndCheck_CL',cal='center',co=('both',5),p='DefultWeightCL')
    button(w=200,h=30,l='Flood',c='artAttrSkinPaintCtx(currentCtx(),e=1,clear=1)')
    separator(p='FloodAndCheck_CL',style="none",h=5)
    button('YJCheckBu',w=200,h=30,l='Check',c='YJCheckPaintValue()')
    
    
    
    ###### the main pointWeightLayout
    columnLayout('PointWeightCL',p='MainCL',vis=0)
    separator(p='PointWeightCL',style="none",h=10)
    rowLayout('PointWeightRL',numberOfColumns=2,columnWidth2=(115, 115),
    cal=[(1,'center'),(2,'center')],p='PointWeightCL')
    button(h=30,w=95,l='Grow',c='YJGrowOrLoopSelect(0)')
    button(h=30,w=95,l='Loop',c='YJGrowOrLoopSelect(1)')
    
    separator(p='PointWeightCL',style="none",h=5)
    rowLayout('PointWeightNBRL',nc=7,cw=[(1,30),(2, 30),(3, 30),(4, 30),(5, 30),(6, 30),(7, 30)],p='PointWeightCL')
    button(h=30,w=30,l='0',c='YJPointSetWeightValListed(0)')
    button(h=30,w=30,l='.1',c='YJPointSetWeightValListed(0.1)')
    button(h=30,w=30,l='.25',c='YJPointSetWeightValListed(0.25)')
    button(h=30,w=30,l='.5',c='YJPointSetWeightValListed(0.5)')
    button(h=30,w=30,l='.75',c='YJPointSetWeightValListed(0.75)')
    button(h=30,w=30,l='.9',c='YJPointSetWeightValListed(0.9)')
    button(h=30,w=30,l='1',c='YJPointSetWeightValListed(1)')
    
    separator(p='PointWeightCL',style="none",h=5)
    rowLayout('PointWeightSWRL',numberOfColumns=2,columnWidth2=(115, 115),
    cal=[(1,'center'),(2,'center')],p='PointWeightCL')
    button(h=30,w=95,l='Set Weight',c='YJPointSetWeightValListed(10)')
    floatField('SetValF',v=0.5,pre=4,min=0,max=1,w=95,h=30)
    
    separator(p='PointWeightCL',style="none",h=5)	
    columnLayout('PointWeightPCL',p='PointWeightCL')
    rowLayout('PointWeightPRL',numberOfColumns=3,columnWidth3=(80, 70,70),cal=[(2,'center'),(3,'center')],p='PointWeightPCL')
    floatField('PlusOrMinusFF',v=0.05,pre=4,min=0,max=1,w=70,h=25)
    button(h=25,w=60,l='+',c='YJPlusOrMiusValue(0)')
    button(h=25,w=60,l='-',c='YJPlusOrMiusValue(1)')
    separator(p='PointWeightPCL',style="none",h=5)
    rowLayout('PointWeightSRL',numberOfColumns=4,columnWidth4=(80, 70,30,35),cal=[(2,'center'),(3,'center'),(4,'center')],p='PointWeightPCL')
    floatField('ZoomVarFF',v=0.95,pre=4,min=0,max=1,w=70,h=25)
    button(h=25,w=60,l='Scale',c='YJPlusOrMiusValue(3)')
    button(h=25,w=30,l='+',c='YJPlusOrMiusValue(4)')
    button(h=25,w=30,l='-',c='YJPlusOrMiusValue(5)')
    ######
    separator(p='PointWeightCL',style="none",h=5)
    rowLayout('CopyPasteRl',p='PointWeightCL',numberOfColumns=2,columnWidth2=(115, 115),cal=[(1,'center'),(2,'center')])
    button(h=30,w=95, label='Copy' ,c='YJCopyWeightVal()')
    button( h=30,w=95,label='Paste',c='PastePotVar()')
    ######
    separator(p='PointWeightCL',style="none",h=5)
    rowLayout('CurSelJntRl',p='PointWeightCL',numberOfColumns=2,columnWidth2=(50, 115))
    text( 'CurSelJnt',label='CurSelJnt:', align='left' )
    text( 'CurSelJntN',label='',w=160,bgc=[0.1,0.5,0.5])
    ###the textScrollList show the effect joints
    columnLayout('PWSJ_CL',p='PointWeightCL')
    separator(p='PWSJ_CL',style="none",h=5)
    textScrollList('PotInfText',p='PWSJ_CL',w=210,h=300,sc='changeCurSelJnt()')
    popupMenu( parent='PotInfText')
    menuItem(l='Lock',c='YJHoldSelJnt("PotInfText")')
    menuItem(l='UnLock',c='YJUnHoldSelJnt("PotInfText")')
    menuItem(l='LockAll',c='YJLockUnlock(1,"PotInfText")')
    menuItem(l='UnLockAll',c='YJLockUnlock(0,"PotInfText")')
    ######
    columnLayout('CopyPasteSave_CL',p='PointWeightCL')
    text( 'CopyPasteSaveTx',label='', vis=0 )





    showWindow('YJWeightWin')

###### Change the weight mode
def YJ_Change_Mode(Paint,Point):
    m=columnLayout('PointWeightCL',q=1,vis=1)
    if m==1 and Point==0:
        scriptJob( k= YJJobNub,f=1)
    elif Point==1:
        YJScrJob()
    columnLayout('DefultWeightCL',e=1,vis=Paint)
    columnLayout('PointWeightCL',e=1,vis=Point)
    if (Paint==1):
        selectMode( object=True )
        modelEditor( 'modelPanel4', e=True,dl='default' ,da='smoothShaded')
        columnLayout('DefultWeightCL',e=1,en=1)
        YJ_changePaintBrush('absolute','solid')
        YJ_changePaintBrushOperation()
        YJ_changeBrushType(3)
        YJGetCurrentList()
        YJTurnToSelText()
        
    
    else:
        #####Sometimes we don't know the current tool(setName) we can use currentCtx()
        setToolTo('selectSuperContext')
        selectMode( component=True )
        selectPriority( jp=1 )
        selectType(jp=1,sp=0,rp=0,cv=1,pv=1,smp=1,lp=1,pr=1)
        



###### Change Paint Brush mode 
def YJ_changePaintBrush(type,Brushyp):
    ArtPaintSkinWeightsTool()
    artAttrSkinPaintCtx(currentCtx(), edit=True, sao=type,stP=Brushyp)
    
#####
def YJ_changeBrushType(m):
    if m==1:
        a=1;b=0;c=0
        artAttrSkinPaintCtx(currentCtx(), edit=True, stP="gaussian")
    if m==2:
        a=0;b=1;c=0
        artAttrSkinPaintCtx(currentCtx(), edit=True, stP="poly")

    if m==3:
        a=0;b=0;c=1
        artAttrSkinPaintCtx(currentCtx(), edit=True, stP="solid")

    symbolCheckBox('gaussianptBrush',e=1,v=a)
    symbolCheckBox('polyBrush',e=1,v=b)
    symbolCheckBox('solidptBrush',e=1,v=c)
#####
def YJ_changePaintBrushOperation():
    TpOp=radioCollection( 'PaintOperation', q=True, select=1 )
    artAttrSkinPaintCtx(currentCtx(), edit=True,sao=TpOp)

#####
def YJ_setPaintValueT(Value):
    if(Value==0):
        Value=floatSliderGrp('PaintValue',q=1,v=1)
        Value=max(0,Value-0.01)
    if(Value==1):
        Value=floatSliderGrp('PaintValue',q=1,v=1)
        Value=min(1,Value+0.01)
    floatSliderGrp('PaintValue',e=1,v=Value)
    YJ_setPaintValue()
#####
def YJ_setPaintValue():
    CurrentPaintValue=floatSliderGrp('PaintValue',q=1,v=1)
    artAttrSkinPaintCtx(currentCtx(), edit=True,val=CurrentPaintValue)   

#####
def GetCurrentObj():
    SelList=ls(sl=1)
    SelListn=len(SelList)
    if SelListn==1:
        CurrentSelectObj=ls(sl=1)
    else:
        yjm.eval('warning "Please select one skined object!"')
    return CurrentSelectObj



######
def changePaintJoint():
    SelectedJnts=textScrollList('JTshow_list',q=1,si=1)
    if not '(Hold)' in SelectedJnts[0]:
        TargetPaintJnt=SelectedJnts[0]
    else:
        TargetPaintJnt=SelectedJnts[0].replace('(Hold)','')
    yjm.eval('setSmoothSkinInfluence %s'%TargetPaintJnt)

#### Hold Text
def YJHoldTextList(InList):
    OutList=[]
    for i in InList:
        if '(Hold)' in i:
            OutList.append(i)
        else:
            i=i+'(Hold)'
            OutList.append(i)
    return OutList   

####
def YJUnHoldTextList(InList):
    OutList=[]
    for i in InList:
        if not '(Hold)' in i:
            OutList.append(i)
        else:
            i=i.replace('(Hold)','')
            OutList.append(i)
    return OutList 

#####
def YJHoldSelJnt(CurTextName):
    n=0
    SelJntNubList=textScrollList(CurTextName,q=1,sii=1)
    OldJntList=textScrollList(CurTextName,q=1,ai=1)
    SelJntList=textScrollList(CurTextName,q=1,si=1)
    NewSelHoldTextList=YJHoldTextList(SelJntList)
    for i in OldJntList:
        if i in SelJntList:
            i=YJToJntName(i)
            setAttr('%s.liw'%i,1)
            CuRNub=SelJntNubList[n]
            NewSelHoldText=NewSelHoldTextList[n]
            textScrollList(CurTextName,e=1,rii=CuRNub)
            textScrollList(CurTextName,e=1,ap=[CuRNub,NewSelHoldText])
            n=n+1
#####

def YJUnHoldSelJnt(CurTextName):
    n=0
    SelJntNubList=textScrollList(CurTextName,q=1,sii=1)
    OldJntList=textScrollList(CurTextName,q=1,ai=1)
    SelJntList=textScrollList(CurTextName,q=1,si=1)
    NewSelUnHoldTextList=YJUnHoldTextList(SelJntList)
    for i in OldJntList:
        if i in SelJntList:
            i=YJToJntName(i)
            setAttr('%s.liw'%i,0)
            CuRNub=SelJntNubList[n]
            NewSelUnHoldText=NewSelUnHoldTextList[n]
            textScrollList(CurTextName,e=1,rii=CuRNub)
            textScrollList(CurTextName,e=1,ap=[CuRNub, NewSelUnHoldText])
            n=n+1
#####
def YJGetCurrentList():
    skinJntList=skinCluster(GetCurrentObj(),q=1,inf=1)
    NewList=[]
    for i in skinJntList:
        JntHoldQ=getAttr('%s.liw'%i)
        if JntHoldQ==1:
            i=i+('(Hold)')
            NewList.append(i)
        else:
            NewList.append(i)
    textScrollList('JTshow_list',e=1,ra=1)

    textScrollList('JTshow_list',e=1,allowMultiSelection=True,append=NewList)
######
def YJToJntName(ImText):
    if '(Hold)' in ImText:
        OutText=ImText.replace('(Hold)','')
    else:
        OutText=ImText
    if '.' in OutText:
        OutTextL=OutText.split('.')
        OutTextZD=OutTextL[0]
        OutText = OutTextZD[:-1]
    return OutText

######
def YJLockUnlock(ImputNub,TextScName):
    m=ImputNub
    OldJntList=textScrollList(TextScName,q=1,ai=1)
    if m==0:
        NewTextList=YJUnHoldTextList(OldJntList)
    elif m==1:
        NewTextList=YJHoldTextList(OldJntList)
    textScrollList(TextScName,e=1,ra=1)
    textScrollList(TextScName,e=1,a=NewTextList)
    skinJntList=skinCluster(GetCurrentObj(),q=1,inf=1)
    for i in skinJntList:
        setAttr('%s.liw'%i,m)
######
def YJCheckPaintValue():
    ButText=button('YJCheckBu',q=1,l=1)
    if ButText=='Check':
        ButText=button('YJCheckBu',e=1,w=200,h=30,l='ExitCheck')
        artAttrSkinPaintCtx(currentCtx(),e=1,colorrangeupper=0 )
    elif ButText=='ExitCheck':
        ButText=button('YJCheckBu',e=1,w=200,h=30,l='Check')
        artAttrSkinPaintCtx(currentCtx(),e=1,colorrangeupper=1 )

######
def YJTurnToSelText():
    TarSel=artAttrSkinPaintCtx(currentCtx(),q=1,inf=1)
    OldJntList=textScrollList('JTshow_list',q=1,ai=1)
    if TarSel in OldJntList:
        textScrollList('JTshow_list',e=1,si=TarSel)
    else:
        TarSel=TarSel+'(Hold)'
        textScrollList('JTshow_list',e=1,si=TarSel)

######
def YJArrayTheJntList(m):
    OldJntList=textScrollList('JTshow_list',q=1,ai=1)
    if m==0:
        OldJntList.sort()
        textScrollList('JTshow_list',e=1,ra=1)
        textScrollList('JTshow_list',e=1,allowMultiSelection=1,append=OldJntList)

    if m==1:
        n=0
        for i in OldJntList:
            if not '(Hold)' in i:
                OldJntList.remove(i)
                OldJntList.insert(n,i)
                n=n+1
        textScrollList('JTshow_list',e=1,ra=1)
        textScrollList('JTshow_list',e=1,allowMultiSelection=True,append=OldJntList)
    if m==2:
        YJGetCurrentList() 

######
def YJGetCurSkinObj():
    CurSelList=ls(sl=1)
    CurSel=CurSelList[-1]
    if '.' in CurSel:
        NCurSel=CurSel.split('.')
        CurSel=NCurSel[0]
    return CurSel
######
def YJgetCurSelPoint():
    CurSelPotList=ls(sl=1)
    CurPotSel=CurSelPotList[-1]
    if ':' in CurPotSel:
        ChangeList=CurPotSel.split(':')
        ChangeFList=ChangeList[0].split('[')
        CurPotSel=ChangeFList[0]+'['+ChangeList[-1]
    return CurPotSel
######
def YJGetCurrentInfList():
    CurPotSel=YJgetCurSelPoint()
    CurSel=YJGetCurSkinObj()
    CurSkinClaName=yjm.eval( 'findRelatedSkinCluster %s'%CurSel)    
    PointInfJntList=skinPercent( CurSkinClaName, CurPotSel, ib=0.000100,q=1,transform=None)
    NewList=[]
    for i in PointInfJntList:
        JntHoldQ=getAttr('%s.liw'%i)
        Value=skinPercent( CurSkinClaName,CurPotSel, ib=0.000100, t=i, query=True )
        NumStr=YJgetShotNumStr(Value)
        if JntHoldQ==1:
            i=i+NumStr+('(Hold)')
            NewList.append(i)
        else:
            i=i+NumStr
            NewList.append(i)
    textScrollList('PotInfText',e=1,ra=1)
    textScrollList('PotInfText',e=1,allowMultiSelection=0,append=NewList)

######
def YJgetShotNumStr(ImputNum):
    Nnum='%.3f'%ImputNum
    NumStr=str(Nnum)
    return NumStr

######
def YJScrJob():
    global YJJobNub

    YJJobNub=scriptJob( e= ["SelectionChanged","YJScrJobButton()"])
######
def YJScrJobButton():
    m=selectMode( q=True,component=True )
    CurSelList=ls(sl=1)
    if m==1 and CurSelList!=[]:
        if objectType(CurSelList[0])=='joint':
            CurselJntO=CurSelList[0]
            CurselJntOL=CurselJntO.split('.')
            CurSelJnt=CurselJntOL[0]   
            TarJnt=text( 'CurSelJntN',e=1,label=CurSelJnt)       
        else:
            YJGetCurrentInfList()
            YjSelectTheEdJnt()
######
def YJGrowOrLoopSelect(InNub):
    if InNub ==0:
        yjm.eval('GrowPolygonSelectionRegion')
    elif InNub==1:
        polySelectSp(loop=1)
######
def YJGetPointTarJnt():
    TarJnt=text( 'CurSelJntN',q=1,label=1)
    return TarJnt

def changeCurSelJnt():
    CurSelJntL=textScrollList('PotInfText',q=1,si=1)
    if CurSelJntL != None:
        CurSelJnt=YJToJntName(CurSelJntL[0])
        TarJnt=text( 'CurSelJntN',e=1,label=CurSelJnt)
       
#####Set Point Value
def YJPointSetWeightVal(SetVal):
    TarJnt=YJGetPointTarJnt()
    TarPotList=ls(sl=1)
    CurSel=YJGetCurSkinObj()
    CurSkinClaName=yjm.eval( 'findRelatedSkinCluster %s'%CurSel) 
    for i in TarPotList:
        skinPercent( CurSkinClaName,i, transformValue=(TarJnt,SetVal))
    YJGetCurrentInfList()
######
def YJPointSetWeightValListed(InSetVal):
    if InSetVal==10:
        SetVal= floatField('SetValF',q=1,v=1)
    else:
        SetVal=InSetVal    
    YJPointSetWeightVal(SetVal)
    YjSelectTheEdJnt()
def YjSelectTheEdJnt():
    TarJnt=YJGetPointTarJnt()
    CurJntList=textScrollList('PotInfText',q=1,ai=1)
    for i in CurJntList:
        JntN=YJToJntName(i)
        if JntN==TarJnt:
            textScrollList('PotInfText',e=1,si=i)

#####
def YJPlusOrMiusValue(sign):
    CurPotSel=YJgetCurSelPoint()
    CurSel=YJGetCurSkinObj()
    CurSkinClaName=yjm.eval( 'findRelatedSkinCluster %s'%CurSel)
    OldPotVar=skinPercent( CurSkinClaName,CurPotSel, ib=0.000100, t=YJGetPointTarJnt(), query=True )
    CurPMVar=floatField('PlusOrMinusFF',q=1,v=1)
    CurZoomVar=floatField('ZoomVarFF',q=1,v=1)
    if sign ==0:
        SetVal=OldPotVar + CurPMVar
        if SetVal >= 1:
            SetVal = 1
    elif sign == 1:
        SetVal=OldPotVar - CurPMVar
        if SetVal <= 0:
            SetVal = 0
    elif sign == 3:
	 SetVal=OldPotVar * CurZoomVar
    elif sign == 4:
        SetVal=OldPotVar + OldPotVar*0.05
        if SetVal >= 1:
            SetVal = 1
    elif sign == 5:
        SetVal=OldPotVar - OldPotVar*0.05
        if SetVal <= 0:
            SetVal = 0
    YJPointSetWeightVal(SetVal)
    YjSelectTheEdJnt()
#####
def YJCopyWeightVal():
    CurPotSel=YJgetCurSelPoint()
    text('CopyPasteSaveTx',e=1,l=CurPotSel)

#####
def PastePotVar():
    CurPotSel=YJgetCurSelPoint()
    CurSel=YJGetCurSkinObj()
    CurSkinClaName=yjm.eval( 'findRelatedSkinCluster %s'%CurSel)
    OrgPotSel=text('CopyPasteSaveTx',q=1,l=1)
    OldPotJnts=skinPercent( CurSkinClaName,CurPotSel, ib=0.000100,q=1,transform=None)
    PointTVList=[]
    for i in OldPotJnts:
        j=skinPercent( CurSkinClaName,OrgPotSel, ib=0.000100, t=i, query=True )
        k=(i,j)
        PointTVList.append(k)
    PointSelList=ls(sl=1)
    for j in PointSelList:
        skinPercent( CurSkinClaName,j,transformValue=PointTVList )
    YJGetCurrentInfList()

#########
def GetPointTVList(CurSkinClaName,CurVtx,PotJnts):

    PointTVList=[]
    for l in PotJnts:
        j=skinPercent( CurSkinClaName,CurVtx, ib=0.000100, t=l, query=True )
        k=(l,j)
        PointTVList.append(k)
    return PointTVList

def YJSaveWeight():
    CurSel=YJGetCurSkinObj()
    CurSkinClaName=yjm.eval( 'findRelatedSkinCluster %s'%CurSel)

    Vtxvar=0
    CurObjVtxList=[]
    MaR=polyEvaluate( v=True)
    while Vtxvar < MaR:
        CurObjVtx=str(CurSel)+'.vtx[%d]'%Vtxvar
        CurObjVtxList.append(CurObjVtx)
        Vtxvar=Vtxvar+1
    CurObjVtxListW=CurObjVtxList
    VerClass={}
    for i in CurObjVtxListW:
        PotJnts=skinPercent( CurSkinClaName,i, ib=0.000100,q=1,transform=None)
        PointTVListN=GetPointTVList(CurSkinClaName,i,PotJnts)
        VerClass[i]=PointTVListN
    VerClassN=VerClass  
    WeightfileP=r'C:\Users\yangjie\Documents\maya\2009\data'
    if not os.path.exists(WeightfileP):
        os.mkdir(WeightfileP)
    Weightfile=r'C:\Users\yangjie\Documents\maya\2009\data\skin.txt'

    VerClassS=open(Weightfile,'w')
    VerClassS.write(str(VerClassN))
    VerClassS.close
#####
def YJLoadWeightVar():
    ###Load Weight
    Weightfile=r'C:\Users\yangjie\Documents\maya\2009\data\skin.txt'
    VerClassL=open(Weightfile,'r')
    VerClassLoad=VerClassL.read()
    exec ("VerClassNew=" + VerClassLoad) 
    VerClassL.close
    VerKeys=list(VerClassNew.keys())
    
    CurSel=YJGetCurSkinObj()
    CurSkinClaName=yjm.eval( 'findRelatedSkinCluster %s'%CurSel)
    for i in VerKeys:
        skinPercent( CurSkinClaName,i,transformValue=VerClassNew[i] )

YJ_weighiTool()