选择所有没有子项的空

Posted

技术标签:

【中文标题】选择所有没有子项的空【英文标题】:Selecting all Empties without Children 【发布时间】:2022-01-23 19:58:50 【问题描述】:

我有一个包含数千个零件的大型结构化模型。在 CAD 导出(到 fbx)期间,文件被简化并移除了许多小部件(如螺钉和垫圈)。但是,在 Blender 中,我现在有很多“空”,下面没有任何孩子。 我想选择所有没有子对象的空对象,这样我就可以将它们全部删除。

【问题讨论】:

【参考方案1】:

我的 python 有点生锈了,我敢肯定,有很多更好的方法可以做到这一点。但是,这是一个可以解决问题的 bpy 脚本。 选择根为空并运行脚本。然后可以删除选定的空。 要获取整个树中的所有空,脚本必须运行多次,直到没有更多的空被选择...

import bpy

root_object = bpy.context.object
empties = []
selected = []

def select_children_recursive(obj_parent):
    for obj in obj_parent.children:
        select_children_recursive(obj)
        if obj.type == 'EMPTY':
            empties.append(obj)


# call the function
select_children_recursive(root_object)

# deselect everyting
bpy.ops.object.select_all(action='DESELECT')

# select all empties that have NO children

for obj in empties:
    if len(obj.children) == 0:
        selected.append(obj)
        obj.select_set(True)


print(' empties were selected'.format(len(selected)))
print('Press x to delete them and re-run this script again multiple times in order to delete all empies throughout the entire structure.')

【讨论】:

以上是关于选择所有没有子项的空的主要内容,如果未能解决你的问题,请参考以下文章

选择所有子项仅包含相同值且没有其他方案的行

如何用快捷键打开注册表里的所有子项?

选择所有子项只有一种状态的行

m2Eclipse中的空目标列表

仅计算两个不同列中的空值并显示在一个选择语句中

如何计算一行中的空列?