2013-11-09 5 views
0

Это код, который я запускаю, но он говорит: «Эти атрибуты недопустимы», как мне перечислять атрибуты/преобразования в моей сцене, чтобы я мог правильно их перечислить. Я попытался использовать cmds.ls (type = 'transform'), но он все равно не работает. Любая помощь приветствуется.Недопустимые атрибуты/атрибуты Python

import maya.cmds as cmds 
def changeXtransformVal(myList, percentage=2.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 thisTransform 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)) 
    transformInScene = cmds.ls(type='transform') 
    # 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 badAttrs 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 = ['sx', 'sy', 'tz', 'ty', 'tx'] 
changeXtransformVal(myList, percentage=2.0) 

ответ

0

У вас есть простая ошибка отступов в нескольких местах. Последний (строка 35):

for attr in myList: 

код является слишком низким. Код по строке 31>:

if thisTransform not in ['front','persp','side','top']: 
    allAttrs = cmds.listAttr(thisTransform, keyable=True, scalar=True) 

Должно быть все на уровне if. Также это не имеет никакого смысла:

allAttrs = [ i for i in badAttrs if i != "visibility" ] 

отпечаток неправильный весь ваш код после этого должен быть на уровне вашего if. Вот центральная часть написана еще раз:

import maya.cmds as cmds 
def changeXtransformVal(myList, percentage=2.0): 
    transformInScene = [i for i in cmds.ls(type='transform') if i not in ['front','persp','side','top'] ] 
    myList = [i for i in myList if i not in ['v','visibility']] 
    for thisTransform in transformInScene: 
     badAttrs = [] 
     for attr in myList: 
      try: 
       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) 
      except TypeError: 
       badAttrs.append(attr) 
     if badAttrs: 
      print "These attributes %s are not valid" % str(badAttrs) 

myList = ['sx', 'sy', 'tz', 'ty', 'tx'] 
changeXtransformVal(myList, percentage=2.0) 

Примечание вложенности немного слишком глубоко рассмотреть вопрос о переходе зацикливание матраса в определении функции.

Смежные вопросы