python simple class add text not working .

I make two python scripts :
First :

import bpy
class addtext:
    def __init__(self,text):
        newText=self.text
        bpy.ops.object.text_add()
        bpy.context.scene.objects.active = bpy.data.objects["Text"]
    def add (self)    
        bpy.ops.object.editmode_toggle()
        bpy.ops.font.delete()


        bpy.ops.font.text_insert(newText)
        bpy.ops.object.editmode_toggle()

… next :

import text_scriptfrom text_script import *
text1=addtext("aaa")

The console error I got is:

Traceback (most recent call last):  File "/using_text.py", line 3, in <module>
  File "/text_script.py", line 10, in __init__
  File "/home/usertest/blender-2.65a-linux-glibc27-i686/2.65/scripts/modules/bpy/ops.py", line 186, in __call__
    ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
TypeError: Calling operator "bpy.ops.font.text_insert" error, expected a string enum in ('INVOKE_DEFAULT', 'INVOKE_REGION_WIN', 'INVOKE_REGION_CHANNELS', 'INVOKE_REGION_PREVIEW', 'INVOKE_AREA', 'INVOKE_SCREEN', 'EXEC_DEFAULT', 'EXEC_REGION_WIN', 'EXEC_REGION_CHANNELS', 'EXEC_REGION_PREVIEW', 'EXEC_AREA', 'EXEC_SCREEN')
Error: Python script fail, look in the console for now...

Note that operators use positional arguments for override_context, execution_context and undo (bool). You need to pass all operator settings as keyword arguments.

    bpy.ops.font.text_insert(text=newText)

See:
http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.ops.html#keywords-and-positional-arguments

Also don’t forget that the text editor is required as context. If you call it from another area, use override_context:

bpy.ops.text.insert({‘edit_text’: bpy.data.texts[‘Text’]}, text=“hi”)

This is something new for me … ( I see your link docs…)
I try to use class with python blender.
So you told me but I understand it’s tow way to run the script :

  1. from another area
  • this mean runing outside blender ?
    -how?
  1. using the Blender Scripting windows with text editor
    -then is need to reload ( Alt-R ) every script I make it?
    -the args :
string argument in: (‘INVOKE_DEFAULT’, ‘INVOKE_REGION_WIN’, ‘INVOKE_REGION_CHANNELS’, ‘INVOKE_REGION_PREVIEW’, ‘INVOKE_AREA’, ‘INVOKE_SCREEN’, ‘EXEC_DEFAULT’, ‘EXEC_REGION_WIN’, ‘EXEC_REGION_CHANNELS’, ‘EXEC_REGION_PREVIEW’, ‘EXEC_AREA’, ‘EXEC_SCREEN’)

can not be avoid ?
Can you take some time and help me with my code…
Also the result of this will be a great tutorial . If you help me I will add it like author …
Thank you . Regards.

from another area

  • this mean runing outside blender ?

No, inside blender, but with the mouse cursor being over the 3d view. Blender areas are the editors in split panes. In the default screen, there’s the info area at the top, the large 3d view in the center, outliner and properties editor on the right side, and the timeline area at the bottom. This is also refered to as “the context” (it’s actually more than that, it can also include certain objects being selected or in a certain mode).