[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31039] trunk/blender/release/scripts/op/ wm.py: rewrote wm.context_set_id() to automatuically match the pointer type with the bpy.data. * iterator by inspecting rna.
Campbell Barton
ideasman42 at gmail.com
Wed Aug 4 15:59:26 CEST 2010
Revision: 31039
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31039
Author: campbellbarton
Date: 2010-08-04 15:59:25 +0200 (Wed, 04 Aug 2010)
Log Message:
-----------
rewrote wm.context_set_id() to automatuically match the pointer type with the bpy.data.* iterator by inspecting rna.
Modified Paths:
--------------
trunk/blender/release/scripts/op/wm.py
Modified: trunk/blender/release/scripts/op/wm.py
===================================================================
--- trunk/blender/release/scripts/op/wm.py 2010-08-04 12:51:32 UTC (rev 31038)
+++ trunk/blender/release/scripts/op/wm.py 2010-08-04 13:59:25 UTC (rev 31039)
@@ -338,23 +338,26 @@
def execute(self, context):
value = self.properties.value
- print(value)
+ data_path = self.properties.data_path
- # TODO! highly lazy, must rewrite
- for lib in dir(bpy.data):
- try:
- id_value = getattr(bpy.data, lib)[value] # bpy.data.brushes["Smooth"]
- except:
- id_value = None
-
- if id_value:
- try:
- print("attempts", id_value)
- exec("context.%s=id_value" % self.properties.data_path)
- break # success
- except:
- pass
+ # match the pointer type from the target property to bpy.data.*
+ # so we lookup the correct list.
+ data_path_base, data_path_prop = data_path.rsplit(".", 1)
+ data_prop_rna = eval("context.%s" % data_path_base).rna_type.properties[data_path_prop]
+ data_prop_rna_type = data_prop_rna.fixed_type
+ id_iter = None
+
+ for prop in bpy.data.rna_type.properties:
+ if prop.rna_type.identifier == "CollectionProperty":
+ if prop.fixed_type == data_prop_rna_type:
+ id_iter = prop.identifier
+ break
+
+ if id_iter:
+ value_id = getattr(bpy.data, id_iter).get(value)
+ exec("context.%s=value_id" % data_path)
+
return {'FINISHED'}
More information about the Bf-blender-cvs
mailing list