我是Python的新手,所以这似乎微不足道。我到处搜索以找到问题的答案,但似乎找不到。
我有一个脚本,就像一个迷你Hypeshade窗口,其主要功能是创建材料并加载用户一次单击选择的所有纹理文件。我想在用户想要将噪声或检查器连接到文件输入之一(例如凹凸,法线等)时使用一个选项。这是通过在Maya中调用“ createRenderNode”窗口来完成的。
现在,我正在处理它,并将其连接到我想要的输入,但是我也想在我的UI中的相应textField中获取此文件的名称,因为当我的函数运行时,它没有,它会得到一个空字符串,因为还没有任何连接。
这是我的代码(我尝试了很多次迭代):
# Error: 'NoneType' object is not iterable
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "<maya console>", line 49, in brwa
# TypeError: 'NoneType' object is not iterable #
import maya.cmds as cmds
import pymel.core as pm
def UI():
if cmds.window("MatWindow", exists = True):
cmds.deleteUI("MatWindow")
mainwindow = cmds.window("MatWindow", t="Dummy UI", bgc=(0.2,0.2,0.2), mnb = False, mxb = False)
cmds.columnLayout()
cmds.rowColumnLayout(nr = 1)
cmds.textFieldGrp('mtNameTxt', l = "Material Name")
cmds.setParent ( '..' )
cmds.columnLayout()
cmds.button("createlamb", l = "Create Lambert", c = 'lamb()')
cmds.setParent ( '..' )
cmds.rowColumnLayout('albclm', nr = 1)
cmds.textFieldGrp('albtxt', l = "Albedo", pht = "Albedo Map")
cmds.iconTextButton('conna', w = 25, h = 20, i = "navButtonUnconnected.png", c = 'brwa()')
cmds.setParent( '..' )
cmds.separator(h = 20)
cmds.text("Insert a name first, then create the lambert, then try to load a texture")
cmds.showWindow()
cmds.window("MatWindow", e = 1, w=550, h=150, sizeable = 0)
UI()
#=========== Lambert ===========#
def lamb():
matName = cmds.textFieldGrp('mtNameTxt', q = True, text = True)
if cmds.objExists(matName) :
cmds.confirmDialog( t = "Error", m = "Material name already exists, please choose another name.", b = "OK")
else :
lambert = cmds.shadingNode("lambert", asShader = True, n = matName)
shading_group = cmds.sets(r = True, nss = True, em = True, n = '%s_SG' %matName)
cmds.connectAttr('%s.outColor' %matName ,'%s.surfaceShader' %shading_group)
def brwa():
matName = cmds.textFieldGrp('mtNameTxt', q = True, text = True)## this gets the material name from the UI
brwsa = '%s.color' %matName
pm.defaultNavigation(destination = brwsa, createNew = 1)
pm.defaultNavigation(destination = brwsa, defaultTraversal = 1) ## this opens the createRenderNode window
brwsafile = cmds.listConnections(brwsa) ## this gets the connected file
for fileName in brwsafile:
def button_cmd(_):
# _ is a dummy argument the button sends, but you can ignore it
cmds.select(fileName)
cmds.iconTextButton('conna', edit = 1, i = "navButtonConnected.png", c = button_cmd)
cmds.textFieldGrp('albtxt', edit = 1, text = fileName)
答案 0 :(得分:0)
按照书面规定,明显的问题是
cmds.iconTextButton('conna', edit = 1, i = "navButtonConnected.png", c = "cmds.select(fileName)")
由于您已将命令指定为字符串,因此'fileName'不会传递给select命令-如果您不小心在全局范围中留下了名为fileName
的变量,这可能会间歇性地起作用;但不会获得循环变量。
基本上,出于说明here的原因,您根本不想将命令作为字符串传递。而是直接传递函数对象。如果您内联定义函数,那么您甚至可以在定义函数的地方抓取相关变量,以简化信息传递(上面的链接会更加详细)。
所以,像这样:
def brwa():
matName = cmds.textFieldGrp('mtNameTxt', q = True, text = True)## this gets the material name from the UI
brwsa = matName + ".diffuse_color"
pm.defaultNavigation(destination=brwsa, defaultTraversal=1) ## this opens the createRenderNode window
brwsafile = cmds.listConnections(brwsa) ## this gets the connected file
for fileName in brwsafile:
def button_cmd(_):
# _ is a dummy argument the button sends, but you can ignore it
cmds.select(fileName)
cmds.iconTextButton('conna', edit = 1, i = "navButtonConnected.png", c = button_cmd)
cmds.textFieldGrp('albtxt', edit = 1, text = fileName)
您的代码段不完整,因此我无法对其进行测试-但这是您提供的代码行中的基本问题。