setQuat() not working in Blender241

Sir
I am facing a problem in Python, if you please help me, it will be a great.

I have developed a module in Blender 237 using Python for opening and closing the mouth of a frog.
That script is using setQuat([A,B,C,D])
but in the new version Blender 241, that script is not working.

For Example:

Open New Blender.237
Create an Armature with 4 bones
Make animation criteria from 1 to 50 frames
and run this script

Script Start

import Blender
from Blender import *
from Blender.Armature import *
from Blender.Armature.Bone import *

ob=Object.Get(‘Armature’)

xbones=ob.getData().bones

Blender.Set(‘curframe’,1)
xbones[0].setQuat([1.000,0.000,0.000,0.0000])
xbones[1].setQuat([1.000,0.000,0.000,0.0000])
xbones[2].setQuat([1.000,0.000,0.000,0.0000])
xbones[3].setQuat([1.000,0.000,0.000,0.0000])
xbones[0].setPose([ROT])
xbones[1].setPose([ROT])
xbones[2].setPose([ROT])
xbones[3].setPose([ROT])
Window.RedrawAll()

Blender.Set(‘curframe’,25)
xbones[0].setQuat([1.000,0.1000,0.2000,0.20000])
xbones[1].setQuat([1.000,0.6000,0.5000,0.40000])
xbones[2].setQuat([1.000,0.1000,0.3000,0.40000])
xbones[3].setQuat([1.000,-0.2000,-0.3000,0.30000])
xbones[0].setPose([ROT])
xbones[1].setPose([ROT])
xbones[2].setPose([ROT])
xbones[3].setPose([ROT])
Window.RedrawAll()

Blender.Set(‘curframe’,50)
xbones[0].setQuat([1.000,0.000,0.000,0.0000])
xbones[1].setQuat([1.000,0.000,0.000,0.0000])
xbones[2].setQuat([1.000,0.000,0.000,0.0000])
xbones[3].setQuat([1.000,0.000,0.000,0.0000])
xbones[0].setPose([ROT])
xbones[1].setPose([ROT])
xbones[2].setPose([ROT])
xbones[3].setPose([ROT])
Window.RedrawAll()

script End

This script is working in Blender.237
Using this type of script I have done a lot of my characters to move their bones.
Now in Blender.241 This script is NOT working.
Can you please help.

Yours KK Rawal

Is any script which can be replaced with setQuat() and setPose()
In the new verision setQuat() is not working.

Can you try using the 2.42a or a recent CVS blender?

  • backporting bugfixes to old blenders isnt dont much (at all?) in blender.

I tried in Blender.242a
It is giving Error at Line 4
ImportError: No modulenamed Bone

Ps: Actually In Blender.237 I have made lot of Functions like
char1.smile()
char2.answer()
char1.Query()
etc
I pass the parameter and the work starts.
All my work will be spoiled.
please…

It is not working in Blender.242a also.

kkrawal, sorry I didnt read your poast right the first time. you pretty much need to recode stuff for blenders new API.

can you plesae give me a link for some good python Armature based tutorial where I
can learn functions similar to setQuat(),setPose()

Try these links :
http://www.zoo-logique.org/3D.Blender/scripts_python/API/Armature-module.html
http://www.zoo-logique.org/3D.Blender/scripts_python/API/Armature.Armature-class.html
http://www.zoo-logique.org/3D.Blender/scripts_python/API/Pose-module.html
http://www.zoo-logique.org/3D.Blender/scripts_python/API/Pose.PoseBone-class.html

Thanks. All these I will try today.
Many Many Thanks

I tried but I am failed. I may be doing some thing Wrong.
I hope setQuat() and setPose() will be restored in Blender.243
Please

they wont be, it should be mostly a syntax update.
rot and quat are interchangeable when it comes to bones since bones always use ‘quat’ for rotation anyway.

I’m also having trouble with setting the rotations for the armatures. It just doesn’t seem like you can set the rotations in a particular order. :frowning:

Since I am not able to use NLA with Python, I am still using Blender.237a because of this type of support of Python. see Below:
suppose there are 3 Frogs
frog1,frog2,frog3
In Blender.237 I am using Python like this
doJump(frog1,230)
seeLeft(frog2,230)
seeRight(frog3,230)
doStand(frog1,260)
In the Python I am giving 1st Parameter is the Armature, 2nd Parameter Frame No.
Only One ACTION will be for Each Armature, which will be updated by Python. No NLA is used at all.
Can you please tell me new Syntex for setPose() and setQuat()

Translated to 2.43, for more info take a read through the API docs, (linked from my sig)
the xbones val isnt used but you may want to access them later.


# Script Start
import Blender
from Blender import *


scn= Scene.GetCurrent()
arm_ob= scn.objects.active
pose = arm_ob.getPose()

act = arm_ob.getAction()
if not act: # Add a pose action if we dont have one
    act = Armature.NLA.NewAction()
    act.setActive(arm_ob)

xbones=arm_ob.data.bones.values()
pbones = pose.bones.values()
print xbones
print pbones


# scn.currentFrame(1)
pbones[0].quat[:] = 1.000,0.000,0.000,0.0000
pbones[1].quat[:] = 1.000,0.000,0.000,0.0000
pbones[2].quat[:] = 1.000,0.000,0.000,0.0000
pbones[3].quat[:] = 1.000,0.000,0.000,0.0000
frame = 1
for i in xrange(4):
    pbones[i].insertKey(arm_ob, frame, Object.Pose.ROT)

pbones[0].quat[:] = 1.000,0.1000,0.2000,0.20000
pbones[1].quat[:] = 1.000,0.6000,0.5000,0.40000
pbones[2].quat[:] = 1.000,0.1000,0.3000,0.40000
pbones[3].quat[:] = 1.000,-0.2000,-0.3000,0.30000
frame = 25
for i in xrange(4):
    pbones[i].insertKey(arm_ob, frame, Object.Pose.ROT)

pbones[0].quat[:] = 1.000,0.000,0.000,0.0000
pbones[1].quat[:] = 1.000,0.000,0.000,0.0000
pbones[2].quat[:] = 1.000,0.000,0.000,0.0000
pbones[3].quat[:] = 1.000,0.000,0.000,0.0000
frame = 50    
for i in xrange(4):
    pbones[i].insertKey(arm_ob, frame, Object.Pose.ROT)
# script End


Hi ideasman,

Has there been any updates in 2.43 for the python Armature interface on top of 2.42?

Thanks a lot.

-D

not sure abt 2.42 - probably will work, added a better example here, where the armature data is also created.
http://members.optusnet.com.au/cjbarton/BPY_API/Pose-module.html

IT IS WORKING…Thanks…
IT IS WORKING…Thanks…
IT IS WORKING…Thanks…
IT IS WORKING…Thanks…

Hi ideasman,

Regarding your example in post 14, how would you extend it to handle different orders of rotations? Say, for a particular bone, the order of rotation is y->x->z, how would specify this particular order of rotation? I’ve tried the following code in 2.4.2 and it didn’t work:


lmat = None
for axis, angle in rot:
	if axis == 'x':
		e = Blender.Mathutils.Euler(angle, 0, 0)
	elif axis == 'y':
		e = Blender.Mathutils.Euler(0, angle, 0)
	else:
		e = Blender.Mathutils.Euler(0, 0, angle)

	if lmat == None:
		lmat = e.toMatrix()
	else:
		lmat = e.toMatrix() * lmat

pb.localMatrix = lmat
pb.insertKey(parentObj, frame+1, [Blender.Object.Pose.ROT])

Is this code supposed to work? Would you expect it to work in 2.4.2/2.4.3?

Thanks a lot.

-D

1 Like

see the bvh importer in blender 2.43rc* - it has a functon that does this exactly.

thanks ideasman, I’ve been an idiot not realising that I’ve been using the wrong
.blender directory all along … your code works like a charm! Thanks a lot!