【问题标题】:Blender Python API : How to select a collection in the Outliner?Blender Python API:如何在 Outliner 中选择一个集合?
【发布时间】:2022-12-15 11:18:53
【问题描述】:

我正在尝试按名称在搅拌机中选择一个集合。我成功地在大纲中找到了集合,并使用以下代码使其成为活动集合

def recurLayerCollection(layerColl, collName):
        found = None
        if (layerColl.name == collName):
            return layerColl
        for layer in layerColl.children:
            found = recurLayerCollection(layer, collName)
            if found:
                return found
    
    layer_collection = bpy.context.view_layer.layer_collection
    layerColl = recurLayerCollection(layer_collection, 'Set')
    bpy.context.view_layer.active_layer_collection = layerColl

这突出显示了我正在寻找但实际上并未选择它的集合,如图所示。

如您所见,它突出显示了集合“Set”,但并未选中它。我该如何选择它?我在 API 中找不到任何可以提供帮助的内容。如果有任何帮助或建议,我将不胜感激。

【问题讨论】:

    标签: python collections blender outliner


    【解决方案1】:

    按名称在搅拌机中选择一个集合

    collections = bpy.context.view_layer.layer_collection.children
    
    for collection in collections:
        if collection.name == "name_of_the_collection_you_want_active":
            bpy.context.view_layer.active_layer_collection = collection
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-21
      • 2022-01-19
      • 2013-02-10
      • 1970-01-01
      • 2010-10-03
      • 2014-08-09
      • 2017-01-29
      相关资源
      最近更新 更多