0 Volts -Maya gallery
Please Register to View Free Download Links
And Unwanted Ads


View previous topic View next topic Go down


Post  Anoop K on Fri Apr 27, 2012 3:03 pm


#          UVShaderTransfer
#          author : Abhiraj K K

import maya.cmds as mc
win = 'UVShaderTrans'
if mc.window (win, exists =1): mc.deleteUI (win)
if mc.windowPref (win, exists = 1): mc.windowPref (win, remove = 1)   

mainCL = mc.columnLayout (adj=1)
mc.separator ('sep1',h=10,st='double')
mc.text ('txt1',l='UVShaderTransfer',fn='tinyBoldLabelFont')
mc.separator ('sep2',h=10,st='double')

mainRL = mc.rowColumnLayout (nc=2)
sourceSL = mc.textScrollList (w=130,ams=1)
targetSL = mc.textScrollList (w=130,ams=1)
mc.button ('sourceB',l="Source",c=lambda event:source())
mc.button ('targetB',l="Target",c=lambda event:target())

mc.setParent (mainCL)
mc.separator ('sep3',h=10,st='double')
mc.button ('UVTrans',l="UV Transfer",c=lambda event:UVTrans())
mc.button ('ShaderTrans',l="Shader Transfer",c=lambda event:ShaderTrans())
mc.text ('txt2',l='User Help: Add suffix to source(eg:_tx) \n Remove history of the source if any!!!')

mc.separator ('sep4',h=10,st='double')
mc.text ('txt3',l="abhirajkk@gmail.com",fn='tinyBoldLabelFont')
mc.separator ('sep5',h=10,st='double')
mc.showWindow (win)

##### List func
def source():
    sel = mc.ls(sl=1)
    sobjs=mc.listRelatives (sel,ad=1,type="transform")
    mc.textScrollList (sourceSL,e=1,ra=1)
    for x in range(size):
        mc.textScrollList (sourceSL,e=1,a=sobjs[x])
def target():
    sel = mc.ls(sl=1)
    sobjs=mc.listRelatives (sel,ad=1,type="transform")
    mc.textScrollList (targetSL,e=1,ra=1)
    for x in range(size):
        mc.textScrollList (targetSL,e=1,a=sobjs[x])
### Uv TransFunc
def UVTrans():
    source = mc.textScrollList(sourceSL,q=1,si=1)
    sshape = mc.listRelatives (source,ad=1)
    target = mc.textScrollList(targetSL,q=1,si=1)
    tempshape = mc.listRelatives (target,ad=1)
    tshape = []
    for x in range (len(tempshape)):
        y= x+x
        if y<(len(tempshape)):
    size = len(source)
    for x in range(size):
        deform = tshape[x]+'Orig'
        if mc.objExists (deform):
            mc.setAttr (deform+'.intermediateObject',0)
            mc.transferAttributes( sshape[x],deform, transferUVs=2, transferColors=2,spa=4)
            mc.delete (deform,ch=1)
            mc.setAttr (deform+'.intermediateObject',1)
            mc.transferAttributes( sshape[x],tshape[x], transferUVs=2, transferColors=2,spa=4)
#### shader Transfer
def ShaderTrans():
   source = mc.textScrollList(sourceSL,q=1,si=1)
   target = mc.textScrollList(targetSL,q=1,si=1)
   sshape = mc.listRelatives(source,ad=1)
   tshape = mc.listRelatives (target,ad=1)
   shape = [shape for shape in tshape if shape.endswith('Orig')]
   for each in shape:
   for x in range(len(sshape)):
      node = mc.listConnections (sshape[x],type='shadingEngine')
      if len(node) == 1:
         mc.sets (tshape[x],e=1,fe=node[0])
      else :
         shader = mc.listConnections (sshape[x],d=0,type='shadingEngine')
         for y in range(len(shader)):
            face = mc.sets (shader[y],q=1)
            for each in face:
               tface = each.split('.')
                         mc.sets (tshape[x]+'.'+tface[1],e=1,fe=shader[y])
          print    'Texture Transferd From '+sshape[x]+' To '+tshape[x]      

Usefull Script for transferring UV and textures

Download UVShaderTransfer

Anoop K

Posts : 9
Points : 36
Reputation : -1
Join date : 2011-12-08

Back to top Go down

View previous topic View next topic Back to top

Permissions in this forum:
You cannot reply to topics in this forum