Maya 2020 fundamentals - modelling the real world
Get halfway through a model and find it's an unworkable mess? Can't add edge loops where you need them? Can't subdivide a mesh properly? If any of this sounds familiar check this course out.
# 1 15-12-2013 , 11:31 PM
Registered User
Join Date: Dec 2013
Posts: 1

Mesh/Shader connection UI

Hello SimplyMaya Community user added image I'm trying to make a small UI which enables the user to list and select objects, and shaders in a scene. this UI would then connect the two with a button... I have the objects and shaders in a textscroll list and it looks perfect however when i press the button to "connect" them it doesn't work...


Code:
import maya.cmds as cmds
def GUI():
    winName="myWindow"

    if ( cmds.window(winName,exists=True)):
        cmds.deleteUI(winName)
    
    cmds.window(winName,title='mesh/shader connector',w=200,h=500)
    cmds.window(winName,q=True,wh=True)
  
    cmds.rowLayout("obj,shd",nc=2,w=200,h=200)
    cmds.columnLayout( adj=True, columnAttach=('left', 5), rowSpacing=10, columnWidth=250 )
    cmds.textScrollList('obj')
    cmds.textScrollList('shd')  
    cmds.textFieldButtonGrp('obj',bl='Import Object', text='Select Object',ed=False, bc='selMultipleObjects()')
    cmds.textFieldButtonGrp('shd',bl='Refresh Shaders', text='Refresh Shaders',ed=False, bc='shadeGrps()')
    cmds.button('Connect()',l='Connect')
    cmds.showWindow()

GUI()

def selObjName():
    sel=cmds.ls(sl=True)[0]
    cmds.textFieldButtonGrp('obj',e=True,text=sel)
    
    
def selMultipleObjects():
    sel=cmds.ls(sl=True)
    cmds.textScrollList('obj',e=True,ra=True)
    cmds.textScrollList('obj',e=True,numberOfRows=len(sel)+10, allowMultiSelection=True,
			append=sel)

def shadeGrps():			
    Shader=cmds.ls(mat=True)
    cmds.textScrollList('shd',e=True,ra=True)
    cmds.textScrollList('shd',e=True,numberOfRows=10,append=Shader)

def Connect():
    cmds.shadingConnection( 'shd', e=True, cs=0 )
    cmds.shadingConnection( 'obj', q=True, cs=True )

I'm pretty much in desperate need of help and any would be deeply appreciated! I tried using cmds.sets, hiergraph, shadeconnections, etc. but to no avail...T_T

Attached Thumbnails

Last edited by anubispf; 15-12-2013 at 11:34 PM.
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads