这是我正在研究的python脚本,我是pyhton脚本的新手,这是我们在学校学习的东西,我需要一些帮助。这是我不断得到的错误,我不明白无效的语法是什么。感谢您的任何帮助。 “import maya.cmds as cmds”,这是我正在处理的程序的一部分,
#Error: line 1: invalid syntax
# File "<maya console>", line 27
# transformInScene = cmds.ls(type='transform')
# ^
# SyntaxError: invalid syntax #
cmds.file(新=真,力=真)
import maya.cmds as cmds
def changeXtransformValue(myList, percentage=1.0):
"""
Changes the value of each transform in the scene by a percentange.
Parameters:
percentage - Percentange to change each transform's value. Default value is 1.
Returns:
Nothing.
"""
*# The ls command is the list command. It is used to list various nodes
# in the current scene. You can also use it to list selected nodes.*
transformInScene = cmds.ls(type='transform')
found = False
for thisTransform in transformInScene:
if i not in ['front','persp','side','top']:
found = True
break
else:
found = False
if found == False:
sphere1 = cmds.polySphere()[0]
cmds.xform(sphere1, t = (0.5, 0.5, 0.5)
*#This is the line where I am having problems*
transformInScene = cmds.ls(type='transform')
sel =cmds.ls(sl=True)
if sel :
transformInScene = sel
# If there are no transforms in the scene, there is no point running this script
if not transformInScene:
raise RuntimeError, 'There are no transforms in the scene!'
badAttrs = list()
# Loop through each transform
for thisTransform in transformInScene:
if thisTransform not in ['front','persp','side','top']:
allAttrs = cmds.listAttr(thisTransform, keyable=True, scalar=True)
allAttrs = [ i for i in allAttrs if i = "visibility" ]
print allAttrs
for attr in myList:
if attr in allAttrs:
currentVal = cmds.getAttr( thisTransform + "." + attr )
newVal = currentVal * percentage
cmds.setAttr(thisTransform + "." + attr, newval)
print "Changed %s. %s from %s to %s" % (thisTransform,attr,currentVal,newVal)
else:
badAttrs.append(attr)
if badAttrs:
print "These attributes $s are not valid" % str()
myList = ["translateX", "translateY", "translateZ", "scaleX"]
changeXtransformVal(myList, percentage=1.0)
这是学校项目的一部分,在修复缩进后,我似乎无法找到问题
答案 0 :(得分:2)
以上一行......
cmds.xform(sphere1, t = (0.5, 0.5, 0.5)
缺少xform
来电的右括号。
答案 1 :(得分:0)
你在“cmds.xform(sphere1,t =(0.5,0.5,0.5)”
行忘记了一个')'看你用两个'('但只有一个')'
最后添加一个:
替换cmds.xform(sphere1,t =(0.5,0.5,0.5) 同 cmds.xform(sphere1,t =(0.5,0.5,0.5))