fix for adding drivers to constraints via python.

the RNA constraint api was checking the current context when getting the constraint driver path and renaming constraints.
this made scripts not work properly so changed this to search for the constraint pose channel user within the object (if the object its self is not the user).
This commit is contained in:
2009-11-26 09:48:53 +00:00
parent 8d9fba6568
commit 9712e3a670
3 changed files with 41 additions and 13 deletions

View File

@@ -92,6 +92,7 @@ int object_data_is_libdata(struct Object *ob);
/* constraints */
struct ListBase *get_active_constraints(struct Object *ob);
struct ListBase *get_constraint_lb(struct Object *ob, struct bConstraint *con, struct bPoseChannel **pchan_r);
struct bConstraint *get_active_constraint(struct Object *ob);
void object_test_constraints(struct Object *ob);

View File

@@ -98,6 +98,33 @@ ListBase *get_active_constraints (Object *ob)
return NULL;
}
ListBase *get_constraint_lb (Object *ob, bConstraint *con, bPoseChannel **pchan_r)
{
if(pchan_r)
*pchan_r= NULL;
if (ELEM(NULL, ob, con))
return NULL;
if((BLI_findindex(&ob->constraints, con) != -1)) {
return &ob->constraints;
}
else if(ob->pose) {
bPoseChannel *pchan;
for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
if((BLI_findindex(&pchan->constraints, con) != -1)) {
if(pchan_r)
*pchan_r= pchan;
return &pchan->constraints;
}
}
}
return NULL;
}
/* single constraint */
bConstraint *get_active_constraint (Object *ob)
{

View File

@@ -92,6 +92,8 @@ EnumPropertyItem constraint_ik_axisref_items[] ={
#ifdef RNA_RUNTIME
#include <stdio.h>
#include "BKE_animsys.h"
#include "BKE_action.h"
#include "BKE_constraint.h"
@@ -168,7 +170,7 @@ static void rna_Constraint_name_set(PointerRNA *ptr, const char *value)
/* make sure name is unique */
if (ptr->id.data) {
Object *ob= ptr->id.data;
ListBase *list= get_active_constraints(ob);
ListBase *list = get_constraint_lb(ob, con, NULL);
/* if we have the list, check for unique name, otherwise give up */
if (list)
@@ -183,19 +185,17 @@ static char *rna_Constraint_path(PointerRNA *ptr)
{
Object *ob= ptr->id.data;
bConstraint *con= ptr->data;
bPoseChannel *pchan= get_active_posechannel(ob);
ListBase *actlist= get_active_constraints(ob);
short inList = 0;
/* check if constraint is in the given list */
if (actlist)
inList= (BLI_findindex(actlist, con) != -1);
/* if constraint is in the list, the list is for the active bone... */
if ((inList) && (actlist != &ob->constraints) && (pchan))
bPoseChannel *pchan;
ListBase *lb = get_constraint_lb(ob, con, &pchan);
if(lb == NULL)
printf("rna_Constraint_path: internal error, constraint '%s' not found in object '%s'\n", con->name, ob->id.name);
if(pchan) {
return BLI_sprintfN("pose.bones[\"%s\"].constraints[\"%s\"]", pchan->name, con->name);
else
return BLI_sprintfN("constraints[\"%s\"]", con->name);
}
return BLI_sprintfN("constraints[\"%s\"]", con->name);
}
static void rna_Constraint_update(bContext *C, PointerRNA *ptr)