Created
November 24, 2014 21:04
-
-
Save jirihnidek/854beb566c2319affb78 to your computer and use it in GitHub Desktop.
Blender Python API example: detection of changes in mesh object (edit mode)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
def cb_scene_update(context): | |
""" | |
""" | |
edit_obj = bpy.context.edit_object | |
if edit_obj is not None and edit_obj.is_updated_data is True: | |
print(edit_obj) | |
#print('>>> Update') | |
class StopCallback(bpy.types.Operator): | |
"""Tooltip""" | |
bl_idname = "scene.stop_callback" | |
bl_label = "Stop Callback" | |
@classmethod | |
def poll(cls, context): | |
return cb_scene_update in bpy.app.handlers.scene_update_post | |
def execute(self, context): | |
print('Removing callback ...') | |
bpy.app.handlers.scene_update_post.remove(cb_scene_update) | |
print('DONE') | |
return {'FINISHED'} | |
class StartCallback(bpy.types.Operator): | |
"""Tooltip""" | |
bl_idname = "scene.start_callback" | |
bl_label = "Start Callback" | |
@classmethod | |
def poll(cls, context): | |
return cb_scene_update not in bpy.app.handlers.scene_update_post | |
def execute(self, context): | |
print('Adding callback ...') | |
bpy.app.handlers.scene_update_post.append(cb_scene_update) | |
print('DONE') | |
return {'FINISHED'} | |
class SceneTestPanel(bpy.types.Panel): | |
""" | |
Creates a Panel in the Scene properties window | |
""" | |
bl_label = "Scene Test Panel" | |
bl_idname = "OBJECT_PT_scene_test" | |
bl_space_type = 'PROPERTIES' | |
bl_region_type = 'WINDOW' | |
bl_context = "scene" | |
def draw(self, context): | |
layout = self.layout | |
scene = context.scene | |
row = layout.row() | |
row = layout.row() | |
row.operator("scene.start_callback") | |
row = layout.row() | |
row.operator("scene.stop_callback") | |
def register(): | |
bpy.utils.register_class(SceneTestPanel) | |
bpy.utils.register_class(StartCallback) | |
bpy.utils.register_class(StopCallback) | |
def unregister(): | |
bpy.utils.unregister_class(SceneTestPanel) | |
bpy.utils.unregister_class(StartCallback) | |
bpy.utils.unregister_class(StopCallback) | |
if __name__ == '__main__': | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment