Blenderのbpyを用いて、テキストオブジェクトを生成後、文字列変換するのに多少手間取ったので忘れないようにメモ

生成したオブジェクトは、サイズ変更、回転、移動など一般的なオブジェクトと同じように扱うことができます。


動作確認環境 : Blender 4.2


bpyによるテキストの生成と文字列変更


bpyを使用して次のようにテキストオブジェクトを生成し、文字列を変更します。

文字列の生成

Python :
# テキスト追加
    bpy.ops.object.text_add(
        enter_editmode=False
    ,   align='WORLD'
    ,   location=(0, 0, 0)
    ,   scale=(1, 1, 1)
    )
    # 名前設定
    bpy.context.object.name = "Text_obj_00"

テキストオブジェクトを生成し、オブジェクトに任意の名前を設定します。


文字列の変更

Python :
# テキスト変換 / 文字列変換
    bpy.data.objects['Text_obj_name'].data.body = "Hello world!" 

生成したテキストオブジェクトを
  1. オブジェクト名指定
  2. 任意の文字「Hello world!」
に変更する操作を行います。


テキストの生成と変形例全文


上記2つを組み合わせた例です。

Python :
def Base_create():
    bpy.ops.object.mode_set(mode='OBJECT')

    # テキスト追加
    bpy.ops.object.text_add(
        enter_editmode=False
    ,   align='WORLD'
    ,   location=(0, 0, 0)
    ,   scale=(1, 1, 1)
    )
    # 名前設定
    bpy.context.object.name = "Text_obj_00"

    # 回転
    object_rotate_func(
        object_list=["Text_obj_00"]
    ,   transform_pivot_point='INDIVIDUAL_ORIGINS'
    ,   radians_num=-90
    ,   orient_axis="X"
    ,   orient_type="GLOBAL"
    )

    # テキスト変換 / 文字列変換
    bpy.data.objects['Text_obj_00'].data.body = "Hello world!" 

    # 文字に厚みを付ける
    bpy.context.object.data.extrude = 0.06
    # 丸みを付ける
    bpy.context.object.data.bevel_depth = 0.02

Base_create()


15行目 :
▼object_rotate_func


27行目 :
テキストオブジェクトに厚みを持たせる

29行目 :
ベベルをかけてオブジェクトに丸みを持たせる


以上
このエントリーをはてなブックマークに追加
コメントを閉じる

コメント

コメントフォーム
記事の評価
  • リセット
  • リセット