Results 1 to 2 of 2
  1. #1

    Setting a 'CHILD_OF' constraint and setting an inverse on an object.

    Code:
    bpy.data.objects['temp2'].select=True;
    bpy.context.scene.objects.active=bpy.data.objects['temp2'];
    
    bpy.ops.object.constraint_add(type='CHILD_OF');
    
    
    context_copy = bpy.context.copy()
    context_copy["constraint"] = bpy.data.objects['temp2'].constraints["Child Of"];
    context_copy["constraint"].target = bpy.data.objects['temp1'];
    #>>>RuntimeError: Error: Could not find constraint data for Child-Of Set Inverse
    bpy.ops.constraint.childof_set_inverse(context_copy);
    
        
    print('done');

    Everything seems to go as planned until the inverse is set. The error coming out in the console is denoted above. The button can be clicked manually to 'Set Inverse' after the script fails at childof_set_inverse() successfully. Is there some reason why yhe constraint data can not be found?

    Thank you



  2. #2
    You might need to add a manual update inbetween before accessing the constraint?
    I would also recommend a low-level access without operators, like:

    Code:
    temp1 = bpy.data.objects['temp1']
    temp2 = bpy.data.objects['temp2']
    const = temp2.constraints.new('CHILD_OF')
    const.target = temp1 
    #just a guess
    const.inverse_matrix = temp1.matrix_world.inverted()
    A similar issue seems to have been discussed here, and there it also was an update problem:

    https://blenderartists.org/forum/sho...redraw-problem



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •