【Blender×Python】イメージデータを名称で取得する方法について徹底解説

Blender

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

# imagesプロパティによる名称を用いたイメージデータの取得
bpy.data.images[IMAGE_NAME]

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

・Blender上で、どの様にPythonを使うの?
・Blender上のPythonで、どの様にイメージデータを名称で取得するの?

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

imagesプロパティによる名称を用いたイメージデータの取得

bpy.data.imagesプロパティの基本構文

bpy.data.images[IMAGE_NAME: str]
→ Image: bpy.types.Image

bpy.data.imagesプロパティの使い方

import bpy

SampleImage = bpy.data.images["Image"]
print(f"Image:\n{SampleImage} {type(SampleImage)}")

print(SampleImage.name)
print(SampleImage.name_full)
print(SampleImage.channels)
print(SampleImage.colorspace_settings)
print(SampleImage.depth)
print(SampleImage.file_format)
print(SampleImage.filepath)
print(SampleImage.generated_color)
print(SampleImage.generated_height)
print(SampleImage.generated_type)
print(SampleImage.generated_width)
print(SampleImage.pixels)
print(SampleImage.size)
print(SampleImage.source)
print(SampleImage.type)
print(SampleImage.views_format)
Image:
<bpy_struct, Image("Image") at 0x000001A04D66B908> <class 'bpy.types.Image'>
Image
Image
4
<bpy_struct, ColorManagedInputColorspaceSettings at 0x000001A04D66BEC0>
32
PNG

<bpy_float[4], Image.generated_color>
1024
BLANK
1024
<bpy_float[4194304], Image.pixels>
<bpy_int[2], Image.size>
GENERATED
UV_TEST
INDIVIDUAL

まとめ

「bpy」(Blender Python API)は、Pythonを使ったBlenderの開発に非常に役立ちます。この記事では、イメージデータを名称で取得する方法を紹介しました。ぜひ活用してみてください。

関連検索ワード

How to get an image data by name?

関連キーワード

blender, python, get, image, name, 取得, イメージ, 画像, 名称, 名前