maya python中列表的setAttr

时间:2016-08-05 01:05:57

标签: python maya mel

我还在弄清楚Python和Maya是如何协同工作的,所以原谅我的无知。所以我试图使用像这样的循环来改变maya中关节列表的属性:

for p in jointList: cmd.getAttr(p, 'radius', .5)

我收到此错误:

Invalid argument 1, '[u'joint1']'. Expected arguments of type ( list, )

我不知道我做错了什么。

4 个答案:

答案 0 :(得分:3)

除非您使用pyMel,否则您需要指定要获取或设置的attr名称和节点。

for getAttr:

for p in jointList:
    val = cmd.getAttr('%s.radius' % (p))

for setAttr:

for p in jointList:
    cmd.setAttr('%s.radius' % (p), .5)

答案 1 :(得分:1)

您需要将节点和频道都指定为第一个参数,例如' joint1.radius'。

在所有关节上将半径设置为.5,您的代码为:

for p in jointList:
    cmd.setAttr(p + '.radius', .5)

答案 2 :(得分:1)

来自文档中的示例:

  

http://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/CommandsPython/getAttr.html

     

http://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/CommandsPython/setAttr.html

当您将对象名称和属性传递给getAttr()函数时,需要将其指定为字符串。

e.g。

translate = cmds.getAttr('pSphere1.translate')

将返回pSphere1

上的translate的属性值

jointList = cmds.ls(type='joint')    
for joint in jointList:
        jointRadius = cmds.getAttr('{}.radius'.format(joint))
        #Do something with the jointRadius below

如果你想设置它

newJointRadius = 20

jointList = cmds.ls(type='joint') 
for joint in jointList:
    cmds.setAttr('{}.radius'.format(joint), newJointRadius)

答案 3 :(得分:-1)

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">hello world</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><%= link_to("往期",issues_path) %></li>
        <li><%= link_to("招聘",jobs_path) %></li>
        <li class="dropdown">
          <ul class="nav navbar-nav" >
              <% if !current_user %>
                  <li><%= link_to("註冊", new_user_registration_path) %> </li>
                  <li><%= link_to("登入", new_user_session_path) %></li>
                <% else %>

                  <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                      <%= gravatar_tag current_user.email, :size => 30, :default => "https://tower.im/assets/default_avatars/path.jpg"%>
                        Hi!, <%= current_user.email %>
                        <b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu" id="bs-example-navbar-collapse-1">
                      <li> <%= link_to("管理后台", admin_users_path) %> </li>
                      <li> <%= link_to("个人信息", account_user_path(current_user)) %> </li>
                      <li> <%= link_to("登出", destroy_user_session_path, method: :delete) %> </li>
                    </ul>
                  </li>
                <% end %>
            </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>