[Bf-python] Making IK flag writable in the Bone class

Jonas Petersen blenderjox at mindfloaters.de
Mon Oct 25 17:34:45 CEST 2004


I updated the patch.

If a bone has no parent a warning is sent like this:

  PyErr_Warn( PyExc_Warning, "bone has no parent!" );

I have added a deprecation warning to hasIK():

  PyErr_Warn( PyExc_DeprecationWarning,
            "hasIK() is deprecated. Please use getIK() instead" );

I have added a getIK() and routed hasIK() to it.

The ik member variables calls getIK()/setIK() respectively.

Now there is:
  bone.hasIK() // depricated
  bone.getIK()
  bone.setIK()
  bone.ik // read
  bone.ik = x // write

I have attached the current patch to this mail. Would be great if 
someone could check and test it.

Here is a basic test python script:

--------------------------------------------
#!BPY
"""
Name: '_IK FLAG TEST'
Blender: 234
Group: 'Object'
Tooltip: ''
"""
import Blender

obj_list = Blender.Object.GetSelected()
for obj in obj_list:

    if obj.getType() == "Armature":
        arm = obj.getData()
        bones = arm.getBones()
       
        for bone in bones:
   
            if bone.getName() == 'RootBone':
                bone.setIK(True)

            if bone.getName() == 'IKBone':
                bone.setIK(False)
                print "setIK(False): ", bone.getIK()
                bone.setIK(True)
                print "setIK(True): ", bone.getIK()
               
                bone.ik = False
                print "ik = False: ", bone.ik
                bone.ik = True
                print "ik = True: ", bone.ik
--------------------------------------------

To use the test script create an armature. Name the root bone 
"RootBone". Name one child bone "IKBone", unset the IK flag and have its 
head be located away from the parents tail. Then select the armature in 
Object Mode and execute "Object"->"Scripts"->"_IK FLAG TEST". Then check 
the result and the console.

One thing I have to mention. Though it seems to be a general Blender 
problem. The output of warnings sent with PyErr_Warn() always follows 
one or more lines of "binary crap ascii characters".

I'm working on WinXP btw. It also happens with the official Blender 234 
release. For example it happens if I call the deprecated Object.get(...) 
(with the non-capital 'g'). Is this a known problem?

Regards,
Jonas


Gilbert, Joseph schrieb:

>Throwing an error is prob a bit extreme. It should prob do nothing and
>send a console warning imo, but others might have a better idea.
>  
>
>Yes getIK() is not really applicable in this case as there is nothing
>really to get other than a bool value. We could change hasIK() to
>getIK() however, this kind of stuff usually ends up breaking the API so
>it would be better to leave hasIK() alone and then put a deprecation
>warning in hasIK() and reroute it to getIK() if that's better.
>
>Yes Bone class must have an ik variable that calls the get/set
>functions.
>
>Hmm.. I don't thing that setIKFlag would be good as you are not only
>setting the flag but also setting a new position for the bones. However
>getIKFlag might be more descriptive than getIK() (although they may not
>be an identifiable pair this way).
>
>Patches go either way. Guess it depends on the size of the code added.
>  
>

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bone-ik-writable-patch.txt
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20041025/6cfdce30/attachment.txt>


More information about the Bf-python mailing list