rewrote wm.context_set_id() to automatuically match the pointer type with the bpy.data.* iterator by inspecting rna.

This commit is contained in:
Campbell Barton 2010-08-04 13:59:25 +00:00
parent 3d0cf3acf1
commit 4906290f0d

@ -338,22 +338,25 @@ class WM_OT_context_set_id(bpy.types.Operator):
def execute(self, context): def execute(self, context):
value = self.properties.value value = self.properties.value
print(value) data_path = self.properties.data_path
# TODO! highly lazy, must rewrite # match the pointer type from the target property to bpy.data.*
for lib in dir(bpy.data): # so we lookup the correct list.
try: data_path_base, data_path_prop = data_path.rsplit(".", 1)
id_value = getattr(bpy.data, lib)[value] # bpy.data.brushes["Smooth"] data_prop_rna = eval("context.%s" % data_path_base).rna_type.properties[data_path_prop]
except: data_prop_rna_type = data_prop_rna.fixed_type
id_value = None
if id_value: id_iter = None
try:
print("attempts", id_value) for prop in bpy.data.rna_type.properties:
exec("context.%s=id_value" % self.properties.data_path) if prop.rna_type.identifier == "CollectionProperty":
break # success if prop.fixed_type == data_prop_rna_type:
except: id_iter = prop.identifier
pass break
if id_iter:
value_id = getattr(bpy.data, id_iter).get(value)
exec("context.%s=value_id" % data_path)
return {'FINISHED'} return {'FINISHED'}