[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [906] contrib/py/scripts/addons/ space_view3d_index_visualiser.py: - Updated for api changes ( changes in poll() and registering).
Bart Crouch
bartius.crouch at gmail.com
Wed Aug 11 17:16:31 CEST 2010
Revision: 906
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=906
Author: crouch
Date: 2010-08-11 17:16:31 +0200 (Wed, 11 Aug 2010)
Log Message:
-----------
- Updated for api changes (changes in poll() and registering).
- All information is now stored as an ID-property on the scene, instead of on each mesh seperately.
- ID-properties are removed when stopping the script.
Disabling the script from the addons-panel while there are still indices being displayed results in an error. Not certain how to solve. Other scripts have the same problem.
Modified Paths:
--------------
contrib/py/scripts/addons/space_view3d_index_visualiser.py
Modified: contrib/py/scripts/addons/space_view3d_index_visualiser.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_index_visualiser.py 2010-08-10 21:25:48 UTC (rev 905)
+++ contrib/py/scripts/addons/space_view3d_index_visualiser.py 2010-08-11 15:16:31 UTC (rev 906)
@@ -32,7 +32,7 @@
bl_addon_info = {
'name': '3D View: Index Visualiser',
'author': 'Bartius Crouch',
- 'version': '2.5.1 2010/07/27',
+ 'version': '2.6.0 2010/08/11',
'blender': (2, 5, 4),
'location': 'View3D > Properties panel > Mesh Display tab',
'warning': '', # used for warning icon and text in addons panel
@@ -54,7 +54,7 @@
# calculate locations and store them as ID property in the mesh
def calc_callback(self, context):
# polling
- if context.mode != 'EDIT_MESH':
+ if context.mode != "EDIT_MESH":
return
# get screen information
@@ -101,17 +101,17 @@
texts+=[loc[0], loc[1], loc[2], loc[3], x, y, 0]
# store as ID property in mesh
- context.active_object.data['IndexVisualiser'] = texts
+ context.scene["IndexVisualiser"] = texts
# draw in 3d-view
def draw_callback(self, context):
# polling
- if context.mode != 'EDIT_MESH':
+ if context.mode != "EDIT_MESH":
return
# retrieving ID property data
try:
- texts = context.active_object.data['IndexVisualiser']
+ texts = context.scene["IndexVisualiser"]
except:
return
if not texts:
@@ -131,78 +131,94 @@
bl_label = "Index Visualiser"
bl_description = "Toggle the visualisation of indices"
- def poll(self, context):
- return context.mode=='EDIT_MESH'
+ @classmethod
+ def poll(cls, context):
+ return context.mode=="EDIT_MESH"
def modal(self, context, event):
context.area.tag_redraw()
# removal of callbacks when operator is called again
- if context.scene.display_indices == -1:
+ if context.scene["display_indices"] == -1:
context.region.callback_remove(self.handle1)
context.region.callback_remove(self.handle2)
- context.scene.display_indices = 0
- return {'CANCELLED'}
+ context.scene["display_indices"] = 0
+ return {"CANCELLED"}
- return {'PASS_THROUGH'}
+ return {"PASS_THROUGH"}
def invoke(self, context, event):
- if context.area.type == 'VIEW_3D':
- if context.scene.display_indices == 0:
+ if context.area.type == "VIEW_3D":
+ if context.scene["display_indices"] == 0:
# operator is called for the first time, start everything
- context.scene.display_indices = 1
+ context.scene["display_indices"] = 1
context.manager.add_modal_handler(self)
self.handle1 = context.region.callback_add(calc_callback,
- (self, context), 'POST_VIEW')
+ (self, context), "POST_VIEW")
self.handle2 = context.region.callback_add(draw_callback,
- (self, context), 'POST_PIXEL')
- return {'RUNNING_MODAL'}
+ (self, context), "POST_PIXEL")
+ return {"RUNNING_MODAL"}
else:
# operator is called again, stop displaying
- context.scene.display_indices = -1
+ context.scene["display_indices"] = -1
+ clear_properties(full=False)
return {'RUNNING_MODAL'}
else:
- self.report({'WARNING'}, "View3D not found, can't run operator")
- return {'CANCELLED'}
+ self.report({"WARNING"}, "View3D not found, can't run operator")
+ return {"CANCELLED"}
+# properties used by the script
+def init_properties():
+ bpy.context.scene["display_indices"] = 0
+ bpy.types.Scene.BoolProperty(attr="display_sel_only", name="Selected only",
+ description="Only display indices of selected vertices/edges/faces",
+ default=True)
+ bpy.types.Scene.BoolProperty(attr="display_vert_index", name="Vertices",
+ description="Display vertex indices", default=True)
+ bpy.types.Scene.BoolProperty(attr="display_edge_index", name="Edges",
+ description="Display edge indices")
+ bpy.types.Scene.BoolProperty(attr="display_face_index", name="Faces",
+ description="Display face indices")
+
+
+# removal of ID-properties when script is disabled
+def clear_properties(full=True):
+ props = ["display_indices", "display_sel_only", "display_vert_index",
+ "display_edge_index", "display_face_index", "IndexVisualiser"]
+ if not full:
+ props = ["IndexVisualiser"]
+ for p in props:
+ if p in bpy.context.scene.keys():
+ del bpy.context.scene[p]
+
+
# defining the panel
def menu_func(self, context):
+ self.layout.separator()
col = self.layout.column(align=True)
col.operator(IndexVisualiser.bl_idname, text="Visualise indices")
row = col.row(align=True)
- row.active = (context.mode=='EDIT_MESH' and \
- context.scene.display_indices==1)
- row.prop(context.scene, 'display_vert_index', toggle=True)
- row.prop(context.scene, 'display_edge_index', toggle=True)
- row.prop(context.scene, 'display_face_index', toggle=True)
+ row.active = (context.mode=="EDIT_MESH" and \
+ context.scene["display_indices"]==1)
+ row.prop(context.scene, "display_vert_index", toggle=True)
+ row.prop(context.scene, "display_edge_index", toggle=True)
+ row.prop(context.scene, "display_face_index", toggle=True)
row = col.row(align=True)
- row.active = (context.mode=='EDIT_MESH' and \
- context.scene.display_indices==1)
- row.prop(context.scene, 'display_sel_only')
- self.layout.separator()
+ row.active = (context.mode=="EDIT_MESH" and \
+ context.scene["display_indices"]==1)
+ row.prop(context.scene, "display_sel_only")
def register():
- bpy.types.Scene.IntProperty(attr="display_indices", default=0)
- bpy.context.scene.display_indices = 0
- bpy.types.Scene.BoolProperty(attr="display_sel_only", name="Selected only",
- description="Only display indices of selected vertices/edges/faces",
- default=True)
- bpy.types.Scene.BoolProperty(attr="display_vert_index", name="Vertices",
- description="Display vertex indices", default=True)
- bpy.types.Scene.BoolProperty(attr="display_edge_index", name="Edges",
- description="Display edge indices")
- bpy.types.Scene.BoolProperty(attr="display_face_index", name="Faces",
- description="Display face indices")
- bpy.types.register(IndexVisualiser)
+ init_properties()
bpy.types.VIEW3D_PT_view3d_meshdisplay.append(menu_func)
def unregister():
- bpy.types.unregister(IndexVisualiser)
+ clear_properties()
bpy.types.VIEW3D_PT_view3d_meshdisplay.remove(menu_func)
if __name__ == "__main__":
- register()
+ register()
\ No newline at end of file
More information about the Bf-extensions-cvs
mailing list