Enter Japanese comments in Blender's text editor

In Blender's Windows environment, Unocode can be displayed in Japanese by TextEdit, In-line Japanese input is not possible.

In the development of add-ons, etc., we usually use other editors, so it doesn't matter much. I found it inconvenient to not be able to input Japanese when writing a little test code or writing notes. I made an add-on that allows you to enter multibyte characters as comments at the end of the selected line of open text image.png Add a panel called Imput Multibyte Comment and an input field to the text tab (Because you can input Japanese on the panel etc. even in the Windows environment. Mac should not support input here either)

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"
    
    #Definition of drawing
    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() #Record the current state so that undo works
        #Get the last line of the selection
        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()
#######################################

It's as simple as confirming that it works, but I hope it helps something.

Recommended Posts

Enter Japanese comments in Blender's text editor
Japanese text preprocessing without for statement in pandas
tse --Introduction to Text Stream Editor in Python
I can't enter characters in the text area! ?? !! ?? !! !! ??
[Blender] Complement Blender's Python API with a text editor
Japanese output in Python
English PDF in Japanese
Remove one-line comments containing Japanese from source code in Python