Maya批量删除选择的中间层级

在使用Maya的时候经常需要对大纲视图进行操作管理,比如下图中要删除选择的中间层级。直接删除的话会连带子节点一起删除,需要先改变链接关系再删除。如果数量过多的话还是比较让人烦恼的。

 

选择需要移除的中间层,运行脚本就可以删除中间层保留子级。

import pymel.core as py


def FindRoot(sl):
    '获取所有根节点'
    root = []
    for obj in sl:
        if not (py.listRelatives(obj, allParents=True, fullPath=1)[0] in sl):
            # print py.listRelatives(obj, allParents = True,fullPath=1,noIntermediate=1)[0]
            root.append(py.listRelatives(obj, allParents=True, fullPath=1, noIntermediate=1)[0])
    return root

def FindChildren(sl):
    '获取所有需要改变链接的子节点'
    Children = []
    for obj in sl:
        if not ([False for chi in py.listRelatives(obj, children=True, fullPath=1, type='transform') if chi in sl]):
           #print py.listRelatives(obj, allDescendents=True, fullPath=1, noIntermediate=1)[-1]
           for x in (py.listRelatives(obj, children=True, fullPath=1, type='transform')):
                Children.append(x) 
    return Children


def ChangeParent(sl):
    py.select(clear=True)
    root = FindRoot(sl)
    children = FindChildren(sl)
    if not (len(root) == 1):
        for chi in children:
            print "children is " + str(chi)
            for roo in root:
                print "Root is " + str(roo)
                if (chi in py.listRelatives(roo, allDescendents=True, fullPath=True)):
                    print 'parent ' + str(chi) + ',' + str(roo)
                    py.parent(str(chi), str(roo))
                    py.select(clear=True)
                    break

    else:
        if not (len(children) == 0):
            print 'parent ' + str(children) + ',' + str(root)    
            py.parent(*(children+root))

    
sl = py.ls(selection=1)
ChangeParent(sl)
py.delete(sl)
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值