【Blender×Python】オブジェクトデータをコレクションデータから取得する方法について徹底解説

Blender

「bpy」とは、PythonからBlenderの機能を呼び出すことができるBlender Python APIのことです。Blenderはオープンソースの3Dアニメーションソフトウェアであり、「bpy」を使うことでBlenderの様々な機能をPythonスクリプトから呼び出して利用することができます。本記事では、「bpy」を用いたオブジェクトデータをコレクションデータから取得する方法を紹介します。

# objectsプロパティによるコレクションデータを用いたオブジェクトデータの取得
"Collection".objects

下記の様な内容で悩んでいる/困っている場合に使える方法を参考までにご共有させて頂きます。

・Blender上で、どの様にPythonを使うの?
・Blender上のPythonで、どの様にオブジェクトデータをコレクションデータから取得するの?

また、「bpy」を使用する上で基礎的な情報は下記の記事で紹介しております。
他の「bpy」のクラスや関数について気になる方はこちらの記事をご覧ください。

objectsプロパティによるコレクションデータを用いたオブジェクトデータの取得

“Collection”.objectsプロパティの基本構文

"Collection".objects
→ CollectionObjects: bpy_prop_collection

“Collection”.objectsプロパティの使い方

import bpy

SampleCollection  = bpy.data.collections["Collection"]
CollectionObjects = SampleCollection.objects

print(f"Collection Objects:\n{CollectionObjects} {type(CollectionObjects)}")
for key, value in CollectionObjects.items():
    print(f"[{key}] Name: {value.name}, Type: {value.type}")

CollectionObjectList = [CollectionObject for CollectionObject in CollectionObjects]
print(f"Collection Object List:\n{CollectionObjectList}")
Collection Objects:
<bpy_collection[2], CollectionObjects> <class 'bpy_prop_collection'>
[Point] Name: Point, Type: LIGHT
[Cube] Name: Cube, Type: MESH
Collection Object List:
[bpy.data.objects['Point'], bpy.data.objects['Cube']]

まとめ

「bpy」(Blender Python API)は、Pythonを使ったBlenderの開発に非常に役立ちます。この記事では、オブジェクトデータをコレクションデータから取得する方法を紹介しました。ぜひ活用してみてください。

関連検索ワード

How to get object data from collection data?

関連キーワード

blender, python, get, object, collection, 取得, オブジェクト, コレクション

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny