How to select only Nurbs curves in scene with Python in Maya (without objects in hierarchy)

huangapple go评论87阅读模式
英文:

How to select only Nurbs curves in scene with Python in Maya (without objects in hierarchy)

问题

请提供一种方法,使用Python在Maya场景中选择所有的Nurbs曲线。但我必须仅选择层次结构中之前或之后没有任何其他对象的曲线。
例如,我有这样的层次结构:


|NurbsCurve1
|组
|NurbsCurve2...

我尝试过这个:

cmds.ls(et="nurbsCurve", ni=True, o=True, r=True)

这段代码选择了整个层次结构,包括“组”。
但我需要仅选择层次结构中没有组的NURBS曲线。
如何使用Python代码做到这一点?
谢谢

英文:

Suggest please a method to select all Nurbs curves in the Maya scene using Python. But I must select only curves without any other objects in the hierarchy before or after.
For example, I have a hierarchy like this:

Group
|NurbsCurve1
|Group
|NurbsCurve2...

I've tried this

cmds.ls(et = "nurbsCurve", ni = True, o = True, r = True)

This code selects the whole hierarchy including "Group"
But I need to select only NURBS curves without groups in the hierarchy.
How can I do this with Python code?
Thanks

答案1

得分: 0

已找到如何自行操作。

All_curves = cmds.ls(type='nurbsCurve', ni=True, o=True, r=True, l=True)
curves_transforms = cmds.listRelatives(All_curves, p=True, type="transform")
cmds.select(curves_transforms)

一切正常。

英文:

figured out how to do it myself

All_curves = cmds.ls(type='nurbsCurve', ni=True, o=True, r=True, l = True)
curves_transforms = cmds.listRelatives(All_curves, p=True, type = "transform")
cmds.select(curves_transforms)

everything works

huangapple
  • 本文由 发表于 2023年1月9日 18:57:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定