import bpy
def main(context):
for ob in context.scene.objects:
print(ob)
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
for t in bpy.data.texts:
bpy.data.texts.remove(t)
bpy.ops.text.open('INVOKE_SCREEN')
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.simple_operator()
If you don’t load another file, make sure to set the reference to the text in text editor spaces to None:
for area in context.screen.areas:
if area.type == 'TEXT_EDITOR':
area.spaces.active.text = None
Thanks CoDEman !
It works fine !
(only changed ‘INVOKE_SCREEN’ to ‘INVOKE_DEFAULT’ to have the opened document active, otherwise the empty screen is active).
Do you have any idea about how to modify the original Blender “text.open” - … layout.operator (“text.open”) - I found it in the original Blender code (…/startup/bl_ui/space_text.py) ?
What is it exactely (module, class …) where is it ? Is it written in C, Py ?