[Bf-python] error handling attempt for posekey inserts
Toni Alatalo
antont at kyperjokki.fi
Tue Jan 16 11:47:17 CET 2007
Toni Alatalo kirjoitti:
> antont (Toni Alatalo) 2007/01/15 17:00:37 CET
> blender/source/blender/python/api2_2x Object.c
> error checking is still needed and more testing too. But at least is <http://projects.blender.org/viewcvs/viewcvs.cgi/blender/source/blender/python/api2_2x/Object.c.diff?r1=1.242&r2=1.243&cvsroot=bf-blender>
>
i tried to add error handling but failed so far, have to move to other
work now so can not finish - dunno why my checks are failing, tried
figuring out with debug prints but they came out as garbage for some
reason which did not make it easier :o
if someone happens to have time now to fix and apply this before release
that might still be possible, otherwise postponed to later .. i tested
the funcs and they work, just the error handling not yet.
the patch is at http://an.org/blender/posekey-errorhandling.diff and
attached here. i left the debug prints in place thinking they'd help
fixing/verifying the error checking / input data validation.
~Toni
P.S. when testing these with the ED walktest.blends it appeared that
pose.fromAction(act, framenum) is not included in the version of the
pypose type in BF now - i had it in my earlier Pose type before
Joseph/ascotan made another one (mainly targeting exporting, & exposing
blender data, whereas my need was being able to use blender anim data
simply from py utilizing existing blender things (there is a simple c
func it called, extract_pose_from_action). so that is one area to look
at in further dev, whether that method could be just added back to Pose,
or if it'd make more sense somewhere else, or is there already something
in the current api with what you can do the same thing nicely (drive
animations with py, basically). i suppose Roland / harkyman has views on
this as BlenderPeople does that kind of things I think.
-------------- next part --------------
*** Object.c.~1.243.~ Mon Jan 15 18:00:36 2007
--- Object.c Tue Jan 16 12:25:56 2007
***************
*** 2393,2400 ****
BPy_Action *sourceact;
char *chanName;
int actframe;
!
!
/* for doing the time trick, similar to editaction bake_action_with_client() */
int oldframe;
int curframe;
--- 2393,2400 ----
BPy_Action *sourceact;
char *chanName;
int actframe;
! char error[256]; /* for py error msgs. using a largish buffer to be on the safe side if someone is using huge channel names (dunno if there is an maximum in blender for those, though. */
!
/* for doing the time trick, similar to editaction bake_action_with_client() */
int oldframe;
int curframe;
***************
*** 2404,2417 ****
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expects an action to copy poses from, a string for chan/bone name, an int argument for frame to extract from the action and finally another int for the frame where to put the new key in the active object.action" );
! extract_pose_from_action(ob->pose, sourceact->action, (float)actframe);
oldframe = G.scene->r.cfra;
G.scene->r.cfra = curframe;
- /* XXX: must check chanName actually exists, otherwise segfaults! */
- //achan = get_action_channel(sourceact->action, chanName);
-
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_X);
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_Y);
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_Z);
--- 2404,2425 ----
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expects an action to copy poses from, a string for chan/bone name, an int argument for frame to extract from the action and finally another int for the frame where to put the new key in the active object.action" );
! if (!get_action_channel(sourceact->action, chanName)) {
! printf("\ncaught invalid chanName\n");
! PyOS_snprintf( error, sizeof(error),
! "No channel called \"%s\" in the given action.", chanName);
! return EXPP_ReturnPyObjError( PyExc_ValueError,
! error );
! }
! else {
! printf("\nchanname found.\n");
! }
!
! extract_pose_from_action(ob->pose, sourceact->action, (float) actframe); //dunno if the float is really necessary
oldframe = G.scene->r.cfra;
G.scene->r.cfra = curframe;
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_X);
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_Y);
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_Z);
***************
*** 2448,2453 ****
--- 2456,2462 ----
/* for doing the time trick, similar to editaction bake_action_with_client() */
int oldframe;
int curframe;
+ char error[256]; /* for py error msgs */
if( !PyArg_ParseTuple( args, "si", &chanName, &curframe ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
***************
*** 2456,2462 ****
oldframe = G.scene->r.cfra;
G.scene->r.cfra = curframe;
! /* XXX: must check chanName actually exists, otherwise segfaults! */
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_X);
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_Y);
--- 2465,2485 ----
oldframe = G.scene->r.cfra;
G.scene->r.cfra = curframe;
! if( self->object->action ) {
! printf("\nhas action\n");
! if (!get_action_channel(self->object->action, chanName)) {
! PyOS_snprintf( error, sizeof(error),
! "No channel called \"%s\" in the given action.", chanName);
! return EXPP_ReturnPyObjError( PyExc_ValueError,
! error );
! }
! printf(".. with channame\n");
! }
! else { //the ob has no current action where to add the key to
! printf("\nno action\n");
! return EXPP_ReturnPyObjError( PyExc_ValueError,
! "This object has no active action to insert keys to.");
! }
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_X);
insertkey(&ob->id, ID_PO, chanName, NULL, AC_LOC_Y);
More information about the Bf-python
mailing list