python - 我可以根据对象的变换值对对象进行分组吗?
问题描述
我正在尝试在 Maya python 中编写一个非常简单的代码,它将根据我的对象的值对它们进行分组。我到目前为止的代码应该可以工作,但它没有。有人可以帮我看看我在这段代码中缺少什么,为什么它没有运行?
mesh= []
for obj in mesh:
Sattr = cmds.getAttr (mesh+'.ty')
if Sattr > 5:
cmds.group (name='Big')
解决方案
meshes = cmds.ls(sl=True) # define the selection to be parsed
to_group = []
for obj in mesh:
Sattr = cmds.getAttr (obj+'.ty') # you want to parse obj and not mesh
if Sattr > 5:
to_group.append(obj) # you want your if to be within your loop
cmds.group(to_group, name='Big') # if you don't provide what you want to group as argument, it will group your selection. So you have two options. Create an empty group and then parent object to it or group every mesh at once
推荐阅读
- sql - 如何在 ga4_obfuscated_sample_ecommerce 公共数据集中查找非活动用户
- android - 如何使用圆形图标图像制作自定义微调器项目?
- laravel - 从数据库返回“创建日期”值 - laravel/vue
- javascript - react-router-bootstrap LinkContainer 组件失败并出现 TypeError (0 , _reactRouterDom.withRouter) is not a function
- javascript - 未捕获的类型错误:无法读取未定义的属性(读取“getidentificadors_contadors”)
- dart - Dart FFI 中的静态链接
- spring-boot - Kubernetes 容器环境变量和 Github Actions 输入变量
- django - Django 从多个模型中选择
- azure - 如何从 azure 文件共享中删除特定时间段之前的文件
- javascript - AjaxControlToolkit ComboBox 选择值手动重置在asp.net c#中不起作用