Trying to connect an object with a shading group in Maya through list and button

Sigchi4life
Category:
Programming
Price: $50 USD

Question description

Maya Python:How do I create two scrolllists with one being objects in scene and other being shading groups and 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 project involves use of cmds.sets and use of hypergraph i think need this done within 2 hrs... majority of it is complete, just need someone to kinda finish it off.

Python UI script.py

Python UI Scene.mb

Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1828 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