我是这个网站的新手,并且还是编程的新手。我一直在Maya2018中使用Python作为我的语言(Pycharm作为我的脚本编辑器)来开发程序生成器。
我收到这样的错误消息:“错误:未定义全局名称'WidthSections'。”
获取“窗口”模型的宽度和高度时遇到问题。我可能以错误的方式进行了处理,但是我尝试将xmax减去xmin来获得宽度,并将ymax减去ymin来获取高度。也许我没有写正确的地方。任何建议都会很有帮助!
代码:
import maya.cmds as cmds
def windowConstruction(numWindowsInwidth = 5, numWindowsInDepth = 3,numFloors = 5):
#Creating Window Panel#
w = 5
h = 8
sx = 5
sy = 6
bWindow = cmds.polyCube(w=w, h=h, sx=sx, sy=sy, n="window")
cmds.polyExtrudeFacet("window.f[21]","window.f[22]","window.f[23]","window.f[16]","window.f[17]","window.f[18]","window.f[11]","window.f[12]","window.f[13]","window.f[6]","window.f[7]","window.f[8]", thickness=-0.2, offset=0.1)
cmds.polyExtrudeFacet("window.f[75]", "window.f[74]","window.f[73]", "window.f[72]", "window.f[71]", "window.f[70]", "window.f[76]", "window.f[77]", "window.f[78]", "window.f[79]", "window.f[80]", "window.f[81]", thickness=1.5)
cmds.polyExtrudeFacet("window.f[111]", "window.f[113]","window.f[115]", "window.f[117]", "window.f[119]", "window.f[121]", "window.f[109]", "window.f[106]", "window.f[104]", "window.f[102]", "window.f[100]", "window.f[98]", thickness=0.3)
cmds.polyExtrudeFacet("window.f[0]","window.f[1]","window.f[2]","window.f[3]","window.f[4]", offset=0.2, thickness=0.4)
cmds.polyExtrudeFacet("window.f[6]","window.f[7]","window.f[8]","window.f[11]","window.f[12]","window.f[13]","window.f[16]","window.f[17]","window.f[18]","window.f[21]","window.f[22]","window.f[23]", offset=0.1)
cmds.polyExtrudeFacet("window.f[6]","window.f[7]","window.f[8]","window.f[11]","window.f[12]","window.f[13]","window.f[16]","window.f[17]","window.f[18]","window.f[21]","window.f[22]","window.f[23]", offset=0.1, thickness=-0.3)
cmds.select("window.e[279]","window.e[274]","window.e[269]","window.e[264]","window.e[259]", "window.e[252]","window.e[246]","window.e[241]","window.e[236]","window.e[231]","window.e[226]", "window.e[219]")
cmds.polyBevel("window.e[279]","window.e[274]","window.e[269]","window.e[264]","window.e[259]", "window.e[252]","window.e[246]","window.e[241]","window.e[236]","window.e[231]","window.e[226]", "window.e[219]")
cmds.polyExtrudeFacet("window.f[110]", "window.f[126]", "window.f[30]", "window.f[31]", "window.f[32]", "window.f[33]","window.f[34]", "window.f[103]", "window.f[119]", "window.f[121]", "window.f[104]","window.f[65]", "window.f[66]", "window.f[67]", "window.f[68]", "window.f[69]", "window.f[96]", "window.f[112]", thickness=1.5)
cmds.select("window.f[110]", "window.f[126]", "window.f[30]", "window.f[31]", "window.f[32]", "window.f[33]","window.f[34]", "window.f[103]", "window.f[119]", "window.f[121]", "window.f[104]","window.f[65]", "window.f[66]", "window.f[67]", "window.f[68]", "window.f[69]", "window.f[96]", "window.f[112]", d=True)
cmds.move(h / 2.0 + 1.49, bWindow, moveY=True)
cmds.move(w / 2.0 + 1.49, bWindow, moveX=True)
cmds.move(8, 0, 0, bWindow[0]+".scalePivot", bWindow[0]+".rotatePivot", absolute=True)
cmds.makeIdentity(bWindow, apply=True, translate=True, t=1, r=1, s=1, n=0)
#Bounding Box of Windows#
xmin, ymin, zmin, xmax, ymax, zmax = cmds.xform(bWindow, query=True, bb=True)
#Duplication/Translation of Windows#
numWindowsInwidth = 5
numWindowsInDepth = 3
numFloors = 5
i = 1
while i <= widthSections:
sectionWidth = cmds.getAttr(bWindow, xmax-xmin)
cmds.duplicate()
cmds.move(-sectionWidth, 0, 0, relative=True)
i += 1
cmds.rotate(0, -90, 0, relative=True)
while i <= depthSections:
sectionWidth = cmds.getAttr(bWindow, xmax-xmin)
cmds.duplicate()
cmds.move(0, 0, -sectionWidth, relative=True)
i += 1
cmds.rotate(0, -90, 0, relative=True)
while i <= widthSections:
sectionWidth = cmds.getAttr(bWindow, xmax-xmin)
cmds.duplicate()
cmds.move(sectionWidth, 0, 0, relative=True)
i += 1
cmds.rotate(0, -90, 0, relative=True)
while i < depthSections:
sectionWidth = cmds.getAttr(bWindow, xmax-xmin)
cmds.duplicate()
cmds.move(0, 0, sectionWidth, relative=True)
i += 1
cmds.select('window*')
while i < heightSections:
sectionHeight = cmds.getAttr(bWindow, xmax-xmin)
cmds.duplicate()
cmds.move(0, sectionHeight, 0, relative=True)
i += 1
#Grouping All Windows#
cmds.select('window*')
cmds.group('window*', name="Windows")
windowConstruction()
答案 0 :(得分:1)
恰如错误消息所述,您有一个变量widthSection
,该变量在未定义的行while i <= widthSections:
上使用。在代码中的某些时候,需要给该变量一个不会发生的值。同样,您可能会发现出于相同原因而未定义depthSections
您有两个未使用的变量numWindowsInwidth
和numWindowsInDepth
。我猜想这些是您实际上应该在该循环中使用的变量,而不是您当前使用的widthSections
和depthSections
。
例如
while i <= numWindowsInwidth:
sectionWidth = cmds.getAttr(bWindow, xmax-xmin)
cmds.duplicate()
cmds.move(-sectionWidth, 0, 0, relative=True)
i += 1