diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-08-04 17:59:25 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-08-04 17:59:25 +0400 |
commit | 4906290f0d3c8e5de91fad104e363a090f6a89f5 (patch) | |
tree | 8444ec6944d6d26a2bd7400cd4b69b5cfd645413 | |
parent | 3d0cf3acf1ea41536dced6d8545e744aa54a105a (diff) |
rewrote wm.context_set_id() to automatuically match the pointer type with the bpy.data.* iterator by inspecting rna.
-rw-r--r-- | release/scripts/op/wm.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/release/scripts/op/wm.py b/release/scripts/op/wm.py index 4f2ec5056ab..a3ae834dbe7 100644 --- a/release/scripts/op/wm.py +++ b/release/scripts/op/wm.py @@ -338,22 +338,25 @@ class WM_OT_context_set_id(bpy.types.Operator): 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'} |