LoginSignup
6
5

More than 3 years have passed since last update.

Blenderのテキストエディッタで日本語コメントを入力する

Last updated at Posted at 2021-01-11

BlenderのWindows環境ではテキストエディットではUnocodeの日本語表示はできるものの
インラインでの日本語入力はできるようになっていません。

アドオンの開発等では通常は他のエディッタを使うことが多いのであまり問題にはならないものの
ちょっとしたテスト用のコードを書いたり、メモ書きをするときに日本語入力ができないのは不便に感じたので
開いているテキストの 選択行の末尾にコメントとしてマルチバイト文字を入力できるアドオンを作ってみました
image.png
テキストタブにImput Multibyte Comment というパネルと入力欄を追加します
(パネル等ではWindows環境でも日本語入力ができるため。Macではここも入力に対応しないはず)

y_TexteditInputComment.py
bl_info = {
    "name" : "Input multibyte character Comment",
    "author" : "Yukimituki",
    "description" : "",
    "blender" : (2, 80, 0),
    "version" : (0, 0, 1),
    "location" : "",
    "warning" : "",
    "category" : "Generic"
}

import bpy
import os
from bpy.props import StringProperty, FloatVectorProperty, BoolProperty

class TEXT_PT_ImputComment(bpy.types.Panel):
    bl_label = "Input Multibyte Comment"
    bl_space_type = 'TEXT_EDITOR'
    bl_region_type = 'UI'
    bl_category = "Text"

    # 描画の定義
    def draw(self, context):
        layout = self.layout
        layout.prop(context.scene, "textedit_comment_txt")
        row = layout.row()
        row.operator("comment.imput")

class TEXT_OT_textimput(bpy.types.Operator):
    bl_idname = "comment.imput"
    bl_label = "imput comment"
    def execute(self, context):
        text = context.space_data.text
        if not text:return {'FINISHED'}
        bpy.ops.ed.undo_push() #アンドゥが効くように現在の状態を記録
        # 選択部分の最終行の取得
        end_line = text.select_end_line_index
        input_text = context.scene.textedit_comment_txt
        text.lines[end_line].body += "# %s" % (input_text)
        return {'FINISHED'}


classes = (
    TEXT_PT_ImputComment,
    TEXT_OT_textimput,
    )


#####################################
def register():
    Scene = bpy.types.Scene
    Scene.textedit_comment_txt = StringProperty(name='text')
    for cls in classes:
        bpy.utils.register_class(cls)


def unregister():
    Scene = bpy.types.Scene
    del Scene.textedit_comment_txt
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)


if __name__ == "__main__":
    register()
#######################################

動くのを確認した程度のシンプルなものですが 何かの手助けになれば幸いです

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5