【Blender Python】5.Blender场景中的集合

概述

这里的"集合"是指Blender场景中的集合。你可以在"大纲视图"面板中看到 图标的,就是集合,可以看做是文件夹,用于分类和整理场景中的对象。

获取场景的集合

python 复制代码
>>> C.scene
bpy.data.scenes['Scene']
python 复制代码
>>> C.scene.collection.name
'Scene Collection'

获取集合的对象

python 复制代码
>>> list(C.scene.collection.objects)
[]

可以看到,"场景集合"下没有直接的子对象,所以返回一个空集。

python 复制代码
>>> list(C.scene.collection.all_objects)
[bpy.data.objects['Cube'], bpy.data.objects['Light'], bpy.data.objects['Camera']]

all_objects会忽略层级关系,将所有层级中的对象全部列出。

使用具体名称获取集合下的对象

python 复制代码
>>> D.collections["Collection"].objects
bpy.data.collections['Collection'].objects

>>> list(D.collections["Collection"].objects)
[bpy.data.objects['Cube'], bpy.data.objects['Light'], bpy.data.objects['Camera']]

遍历输出集合下的对象名称

python 复制代码
>>> objs = D.collections["Collection"].objects
>>> for obj in objs:
...     print(f"obj name is:{obj.name}" )
...     
obj name is:Cube
obj name is:Light
obj name is:Camera

这里,使用的Python的格式化字符串f-string形式。

创建和添加新的集合

python 复制代码
>>> c = D.collections.new("c2")              # 创建一个新的集合,并命名为c2
>>> C.scene.collection.children.link(c)      # 添加到场景的大纲视图

总结

本节介绍Blender中的集合,以及在Blender Python中的获取以及创建。内容不详之处,后续改进。

相关推荐
鄃鳕2 分钟前
Flask【python】
后端·python·flask
weixin_46685 分钟前
Python编程之面向对象
开发语言·人工智能·python
Lynnxiaowen44 分钟前
今天我们学习python编程常用模块与面向对象
运维·python·学习·云计算
一头生产的驴1 小时前
java整合itext pdf实现固定模版pdf导出
java·python·pdf
魔都吴所谓1 小时前
【python】快速实现pdf批量去除指定位置水印
java·python·pdf
YFCodeDream1 小时前
MLLM技术报告 核心创新一览
python·gpt·aigc
夜幽青玄2 小时前
mybatis-plus调用报 org.springframework.dao.DataIntegrityViolationException 错误处理
开发语言·python·mybatis
电子云与长程纠缠3 小时前
Blender入门学习01
学习·blender
qq_546937273 小时前
Blender霓虹灯牌发光标志店招门牌生成器插件 Procedural Signs V2.0.0+预设包
blender
这里有鱼汤4 小时前
📊量化实战篇:如何计算RSI指标的“拥挤度指标”?
后端·python