I try to improve my "comment", uncomment", "copy" and "cut" command in the text editor and i'd like to know if it was possible to print the number and the index of selected lines in the text editor. I'd like to comment or uncomment all selected lines. This is the code i'm using to comment:
class CustomComment(bpy.types.Operator):
''' Auto comment with a space after # '''
bl_idname = "text.custom_comment"
bl_label = "Custom comment"
def execute(self, context):
base = context.space_data.text.current_line.body
bpy.ops.text.select_line()
if " " in base:
bpy.ops.text.move(type='LINE_BEGIN')
bpy.ops.text.move(type='NEXT_WORD')
bpy.ops.text.insert(text="# ")
else:
bpy.ops.text.move(type='LINE_BEGIN')
bpy.ops.text.insert(text="# ")
return {'FINISHED'}
context.space_data.text.current_line_index
, which is the first line if multiple are selected.Print()
will output to the terminal or console that blender was started. $\endgroup$