Clicksor
UVShaderTransfer.py
Page 1 of 1
UVShaderTransfer.py
- Code:
# 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)
mc.window(win,wh=(300,400),s=1,t='UVShaderTrans')
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")
size=len(sobjs)
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")
size=len(sobjs)
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)):
tshape.append(tempshape[y])
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)
else:
mc.transferAttributes( sshape[x],tshape[x], transferUVs=2, transferColors=2,spa=4)
mc.delete(tshape[x],ch=1)
#### 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:
tshape.remove(each)
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
[You must be registered and logged in to see this link.]
Anoop K- Posts : 9
Points : 36
Reputation : -1
Join date : 2011-12-08
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum