Scripted Constraints on Bones fail #19422

Closed
opened 2009-09-20 20:17:12 +02:00 by Ryan Cushman · 6 comments

%%%When you try to apply constraints to bones using the python wrappers two things happen:

  1. they get applied to the general armature object instead of the bone

  2. Instead of going to the desired target they go to a newly created empty.

the second problem happens with all constraints that I can tell but the first one doesn't effect IK constraints. In my blend file, if you just run the script at the bottom you can see the problem at work. The script should copyLoc the offset bone to the main chain but instead it creates a new empty and constrains the armature object to it.

OS-- Mac OSX 10.6.1 (same problem happened on 10.5 though)
RAM -- 2GB
Blender: 2.5 --confirmed on 23237 and 23358%%%

%%%When you try to apply constraints to bones using the python wrappers two things happen: 1) they get applied to the general armature object instead of the bone 2) Instead of going to the desired target they go to a newly created empty. the second problem happens with all constraints that I can tell but the first one doesn't effect IK constraints. In my blend file, if you just run the script at the bottom you can see the problem at work. The script should copyLoc the offset bone to the main chain but instead it creates a new empty and constrains the armature object to it. OS-- Mac OSX 10.6.1 (same problem happened on 10.5 though) RAM -- 2GB Blender: 2.5 --confirmed on 23237 and 23358%%%
Author

Changed status to: 'Open'

Changed status to: 'Open'
Member

%%%Assigning to self. I'll check this out when I get time.

Just reading the description, I think I should mention a few things:

  1. Are you using the object or armature/pose version of the constraint adding operator?
  2. Are the desired targets selected, and is the object/armature you're adding bones to active and in posemode?%%%
%%%Assigning to self. I'll check this out when I get time. Just reading the description, I think I should mention a few things: 1) Are you using the object or armature/pose version of the constraint adding operator? 2) Are the desired targets selected, and is the object/armature you're adding bones to active and in posemode?%%%
Author

%%%The armature is in pose mode and the desired bones ".selected" flags are toggled to true. As far as which operator, I used the same operator that the console reports is used when you implement the constraint manually. %%%

%%%The armature is in pose mode and the desired bones ".selected" flags are toggled to true. As far as which operator, I used the same operator that the console reports is used when you implement the constraint manually. %%%
Member

%%%Ok, checking this out a bit, my first point still stands.

  1. You should be using
    bpy.ops.pose.constraint_add...
    instead of the 'object' version.
    This solves the issue of which context the constraint gets added in.

  2. Secondly, this appears to be related to the 'context' bugs we have (i.e. constraint operators rely on some context info which is only available in 3D-View). One way to currently get around this is to define you script as an operator. To do this, add the
    following code before your existing script lines (make sure you indent your code properly
    though)


import bpy;

Define the operator

class POSE_OT_my_rigging_operator(bpy.types.Operator):
'''
Add description here
'''
idname = "pose.my_rigging_operator"
label = "Add constraint (special)"

def execute (self, context):
        # !!! < ADD YOUR CODE HERE >!!!
          return('FINISHED', );

%%%

%%%Ok, checking this out a bit, my first point still stands. 1) You should be using bpy.ops.pose.constraint_add... instead of the 'object' version. This solves the issue of which context the constraint gets added in. 2) Secondly, this appears to be related to the 'context' bugs we have (i.e. constraint operators rely on some context info which is only available in 3D-View). One way to currently get around this is to define you script as an operator. To do this, add the following code before your existing script lines (make sure you indent your code properly though) -------------------- import bpy; # Define the operator class POSE_OT_my_rigging_operator(bpy.types.Operator): ''' Add description here ''' __idname__ = "pose.my_rigging_operator" __label__ = "Add constraint (special)" def execute (self, context): # !!! < ADD YOUR CODE HERE >!!! ``` return('FINISHED', ); ``` %%%
Member

%%%This has probably been fixed for Durian already in the last few weeks.%%%

%%%This has probably been fixed for Durian already in the last few weeks.%%%
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#19422
No description provided.