[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32117] trunk/blender/source/blender/ python/intern/bpy_rna.c: py/ rna keyframe functions can now key longer paths if called from an ID block.

Campbell Barton ideasman42 at gmail.com
Sat Sep 25 12:11:36 CEST 2010


Revision: 32117
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32117
Author:   campbellbarton
Date:     2010-09-25 12:11:36 +0200 (Sat, 25 Sep 2010)

Log Message:
-----------
py/rna keyframe functions can now key longer paths if called from an ID block.
eg, bpy.context.object.keyframe_insert("soft_body.plastic")

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2010-09-25 08:31:58 UTC (rev 32116)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2010-09-25 10:11:36 UTC (rev 32117)
@@ -1979,26 +1979,46 @@
 static int pyrna_struct_anim_args_parse(PointerRNA *ptr, const char *error_prefix, const char *path,
 	char **path_full, int *index)
 {
+	const int is_idbase= RNA_struct_is_ID(ptr->type);
 	PropertyRNA *prop;
+	PointerRNA r_ptr;
 	
 	if (ptr->data==NULL) {
 		PyErr_Format(PyExc_TypeError, "%.200s this struct has no data, can't be animated", error_prefix);
 		return -1;
 	}
 	
-	prop = RNA_struct_find_property(ptr, path);
-	
+	/* full paths can only be given from ID base */
+	if(is_idbase) {
+		int r_index= -1;
+		if(RNA_path_resolve_full(ptr, path, &r_ptr, &prop, &r_index)==0) {
+			prop= NULL;
+		}
+		else if(r_index != -1) {
+			PyErr_Format(PyExc_ValueError, "%.200s path includes index, must be a separate argument", error_prefix, path);
+			return -1;
+		}
+		else if(ptr->id.data != r_ptr.id.data) {
+			PyErr_Format(PyExc_ValueError, "%.200s path spans ID blocks", error_prefix, path);
+			return -1;
+		}
+	}
+    else {
+		prop = RNA_struct_find_property(ptr, path);
+		r_ptr= *ptr;
+    }
+
 	if (prop==NULL) {
 		PyErr_Format( PyExc_TypeError, "%.200s property \"%s\" not found", error_prefix, path);
 		return -1;
 	}
 
-	if (!RNA_property_animateable(ptr, prop)) {
+	if (!RNA_property_animateable(&r_ptr, prop)) {
 		PyErr_Format(PyExc_TypeError, "%.200s property \"%s\" not animatable", error_prefix, path);
 		return -1;
 	}
 
-	if(RNA_property_array_check(ptr, prop) == 0) {
+	if(RNA_property_array_check(&r_ptr, prop) == 0) {
 		if((*index) == -1) {
 			*index= 0;
 		}
@@ -2008,19 +2028,24 @@
 		}
 	}
 	else {
-		int array_len= RNA_property_array_length(ptr, prop);
+		int array_len= RNA_property_array_length(&r_ptr, prop);
 		if((*index) < -1 || (*index) >= array_len) {
 			PyErr_Format( PyExc_TypeError, "%.200s index out of range \"%s\", given %d, array length is %d", error_prefix, path, *index, array_len);
 			return -1;
 		}
 	}
 	
-	*path_full= RNA_path_from_ID_to_property(ptr, prop);
-
-	if (*path_full==NULL) {
-		PyErr_Format( PyExc_TypeError, "%.200s could not make path to \"%s\"", error_prefix, path);
-		return -1;
+	if(is_idbase) {
+		*path_full= BLI_strdup(path);
 	}
+	else {
+		*path_full= RNA_path_from_ID_to_property(&r_ptr, prop);
+	
+		if (*path_full==NULL) {
+			PyErr_Format( PyExc_TypeError, "%.200s could not make path to \"%s\"", error_prefix, path);
+			return -1;
+		}
+	}
 
 	return 0;
 }





More information about the Bf-blender-cvs mailing list