Trying to connect an object with a shading group in Maya

Dec 16th, 2013
HelloWorld
Category:
Programming
Price: $100 USD

Question description

How do I create two scrolllists with one being objects in scene and other being shading groups.allow user to select one from each and connect them when button is pressed
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 )

   
 



   
  the connect button doesn't work... any alternate way of doing this?


Tutor Answer

(Top Tutor) Daniel C.
(997)
School: New York University
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
Five Star Tutor
Dec 3rd, 2016
" Outstanding Job!!!! "
kpcutie
Nov 19th, 2016
" Excellent job "
Joemoe
Nov 10th, 2016
" <3 it, thanks for saving me time. "
Hemapathy
Nov 6th, 2016
" all I can say is wow very fast work, great work thanks "
pmallory
Oct 28th, 2016
" Totally impressed with results!! :-) "
kevin12622
Oct 14th, 2016
" Goes above and beyond expectations ! "
kiln82
Oct 5th, 2016
" awesome work thanks "
likeplum4
Sep 22nd, 2016
" Excellent work as usual "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1822 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors