From f956e94d131c55625a03569a7bb19d36d4aac9d3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 23 Aug 2010 05:36:21 +0000 Subject: collection attributes can now be resolved with by rna this now works... bpy.context.scene.path_resolve("objects.active.location") Also added an option to coerce the property into a native pytype. --- source/blender/makesrna/intern/rna_access.c | 47 ++++++++++++++++++----------- 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'source/blender/makesrna/intern/rna_access.c') diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 73af75ca960..cdb032b54af 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -2949,7 +2949,7 @@ int RNA_path_resolve_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA *prop; PointerRNA curptr, nextptr; char fixedbuf[256], *token; - int type, len, intkey; + int type, intkey; prop= NULL; curptr= *ptr; @@ -3001,33 +3001,44 @@ int RNA_path_resolve_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, break; case PROP_COLLECTION: if(*path) { - /* resolve the lookup with [] brackets */ - token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1); - - if(!token) - return 0; - - len= strlen(token); + if(*path == '[') { + /* resolve the lookup with [] brackets */ + token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1); + + if(!token) + return 0; + + /* check for "" to see if it is a string */ + if(rna_token_strip_quotes(token)) { + RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr); + } + else { + /* otherwise do int lookup */ + intkey= atoi(token); + RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr); + } - /* check for "" to see if it is a string */ - if(rna_token_strip_quotes(token)) { - RNA_property_collection_lookup_string(&curptr, prop, token+1, &nextptr); + if(token != fixedbuf) { + MEM_freeN(token); + } } else { - /* otherwise do int lookup */ - intkey= atoi(token); - RNA_property_collection_lookup_int(&curptr, prop, intkey, &nextptr); - } + PointerRNA c_ptr; + + /* ensure we quit on invalid values */ + nextptr.data = NULL; - if(token != fixedbuf) - MEM_freeN(token); + if(RNA_property_collection_type_get(&curptr, prop, &c_ptr)) { + nextptr= c_ptr; + } + } if(nextptr.data) curptr= nextptr; else return 0; } - + break; default: if (index==NULL) -- cgit v1.2.3