I need to update my text every time I alter my mesh in edit or object mode or if I edit the Tool panel. I use this script:
# [snip]
# line 308
def update_scene(context):
obj = bpy.context.active_object
if obj.is_updated or obj.data.is_updated:
handle_add(self, context)
print("%s - Object data is_updated (pre)" % obj.data.name)
def handle_add(self, context):
VIEW3D_OT_ADH_display_text._handle = bpy.types.SpaceView3D.draw_handler_add(
draw_text_callback,
(self, context),
'WINDOW', 'POST_PIXEL')
def handle_remove(context):
_handle = VIEW3D_OT_ADH_display_text._handle
if _handle != None:
bpy.types.SpaceView3D.draw_handler_remove(_handle, 'WINDOW')
VIEW3D_OT_ADH_display_text._handle = None
class VIEW3D_OT_ADH_display_text(bpy.types.Operator):
bl_idname = "view3d.adh_display_text"
bl_label = "Display text"
_handle = None
@classmethod
def poll(cls, context):
return update_scene not in bpy.app.handlers.scene_update_post
def execute(self, context):
st = context.window_manager.show_text
handle_add(self, context)
bpy.app.handlers.scene_update_post.append(update_scene)
st.enabled = True
return{'FINISHED'}
class VIEW3D_OT_ADH_remove_text(bpy.types.Operator):
bl_idname = "view3d.adh_remove_text"
bl_label = "Remove text"
@classmethod
def poll(cls, context):
return update_scene in bpy.app.handlers.scene_update_post
def execute(self, context):
st = context.window_manager.show_text
handle_remove(context)
bpy.app.handlers.scene_update_post.remove(update_scene)
st.enabled = False
return {'FINISHED'}
But when I run the script like that, the console shows the following error:
line 312, in update_scene
NameError: name 'self' is not defined
If I add self in the update_scene arguments, another error shows in the console:
TypeError: update_scene() missing 1 required positional argument: 'context'
I have not managed to solve this problem, which is likely an easy fix. How can I do that please ?
draw_text_callback
$\endgroup$draw_text_callback
function isn't so important. $\endgroup$draw_text_callback
to decide if you could safely removeself
from its args-list $\endgroup$