Read a posespace matrix

Hi to all !

(edit: please , see the last post)

This is my first try whit Python , I have read and write the pose of my bone in the armature.

Right now, This is my last try :


for arm in arms.values():
   
 for bone in arm.bones.values():
            
        if (bone.name == 'Posizione') or (bone.name == 'Rotazione'):
            
            ob = Blender.Object.Get('Armature')
            pose = ob.getPose()
            posebone = pose.bones[bone]
            restbone = ob.data.bones[bone]
            print restbone
            print posebone
            
            SaveBone(bone)
    

I want to save the pose of Bones whit name ‘posizione’ and ‘rotazione’

But posebone return ‘none’ and restbone make an error…

I have no access to the pose matrix ( I think I need to save this matrix for save the actual posing of my 2 bones)

Thanks for help

Marco

nobody want help a students ? :spin:

BTW… now the code is :

for saving posedata :

import math 
 
 
import Blender 
import bpy 
import BPyMessages 
 
from Blender import * 
from Blender.Mathutils import * 
 
# settings
 
FileSavePath = "/windows/Bone.txt" 
 
FileSave = open(FileSavePath,'w') 
 
 
 
 
def SaveBone(bonename): 
    scn= Scene.GetCurrent() 
    ob = Blender.Object.Get('Armature') 
    pose = ob.getPose() 
    posebone = pose.bones[bonename] 
     
    Blender.Set('curframe', 1) 
     
     
    FileSave.write(bonename + '
'); 
    armspace = posebone.poseMatrix 
     
    x = 0 
       
    print '
 saving matrix 4x4 pose ' + bonename 
    print armspace 
 
         
    while (x < 4): 
        y = 0 
         
        while (y < 4): 
            strValore = str(armspace[x][y]) 
            #print x,y , armspace[x][y] 
            FileSave.write(strValore + '
'); 
             
            y= y + 1 
        x = x + 1 
         
 
 
 
 
arms = Armature.Get() 
 
for arm in arms.values(): 
     
    SaveBone('Posizione') 
    SaveBone('Rotazione') 
     
 
FileSave.close()        

Load Data :


from Blender import Armature 
from Blender.Mathutils import * 
import math 
 
 
import Blender 
import bpy 
import BPyMessages 
 
from Blender import * 
from Blender.Mathutils import * 
 
 
 
 
 
def LoadBone(bonename): 
    print ' LoadBone : ' + bonename 
    scn= Scene.GetCurrent() 
    ob = Blender.Object.Get('Armature') 
    pose = ob.getPose() 
    posebone = pose.bones[bonename] 
    print "

 Attuali settaggi 

" 
    armspace = posebone.poseMatrix 
    print armspace 
    print "

" 
     
     
     
    for arm in arms.values(): 
        for bone in arm.bones.values(): 
                if (bone.name == bonename): 
                    print 'found : ' + bonename 
                     
                    x = 0 
                    while (x < 4): 
                        y = 0 
                         
                        while (y < 4): 
                            valore = FileSave.readline() 
                             
                            #print x, y , float(valore) 
                              
                            posebone.poseMatrix[x][y] = float(valore) 
                              
                            y= y + 1 
                        x = x+ 1 
                    print '
 Check new matrix : in 
'     
                    print posebone.poseMatrix 
 
  
 
# impostazioni 
 
 
FileSavePath = "/windows/Bone.txt" 
FileSave = open(FileSavePath,'r') 
 
arms = Armature.Get() 
 
while 1 == 1: 
    linea = FileSave.readline()  
    
    if (linea == ''): 
        break 
     
    if (linea =='Posizione
'): 
        print '
 recupero Posizione 
' 
        LoadBone('Posizione') 
         
    if (linea =='Rotazione
'): 
        print '
 recupero Rotazione 
' 
        LoadBone('Rotazione') 
     
 
 
FileSave.close()

But I still have problem whit setting posemode

  1. move the 2 bones (controls) and run the savepose script

  2. moving away the the old position the bones

  3. Run the second script.
    I have a bit of delay to see the new position of the bones and If I try to move the bones the widget is where the bone was In point 2 !

    HELP !

You can fine my sample in http://www.kino3d.com/forum/download.php?id=4611

http://www.kino3d.com/forum/files/errore_618.png

I have an update :
My only problem is that delay time for see the new position

How to call a refresh ?

Thanks

import Blender
from Blender import *


scn= Scene.GetCurrent()
ob = Blender.Object.Get('Armature')
pose = ob.getPose()
posebone = pose.bones['Bone']
#print posebone.poseMatrix
print "
"

print posebone.loc

#Blender.Set('curframe', 1)

posebone.loc[0] = 0 
posebone.loc[1] = -1
posebone.loc[2] = 1

# 1 try to move the bone and see what appens to the shell

# the problem is that the new position came too whit a delay
# HOW TO REFRESH AUTOMATICALLY ?

Here there is an easy blend whit the problem
move the bone e press alt+p
the bone now is nex the center but you still see it in an other position until you call a refresh (for sample manually go in edit mode and after came back to posemode)

http://www.kino3d.com/forum/download.php?id=4616

i’m starting with python too, but i’ve no great experience to help… anyways i’m trying to improve a script that copies UVs from one object to another (or various) that share the same topology. But i’m gonna download yours to see and think a little… :wink:

Thanks,

I just doesnt know how to refresh the 3d view after that my script modified the scene.

This is my final code for this experiments :

import Blender
from Blender import *


scn= Scene.GetCurrent()
ob = Blender.Object.Get('Armature')
pose = ob.getPose()
posebone = pose.bones['Bone']

#print posebone.poseMatrix
print "
"

print posebone.loc[0]
print posebone.loc[1]
print posebone.loc[2]


Blender.Set('curframe', 1)



posebone.loc[0] = 0 
posebone.loc[1] = -1
posebone.loc[2] = 1
print '
 matrice adesso : 
'
#print posebone.size

print posebone.loc[0]
print posebone.loc[1]
print posebone.loc[2]

print ' 
  '
pbones = pose.bones.values()
frame = 50      
act = ob.getAction()

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


#for pbone in pbones: # set bones to no rotation
 #   pbone.quat[:] = 1.000,0.000,0.000,0.0000
  #  pbone.insertKey(ob, frame, Object.Pose.LOC)
    
#posebone.update()
#Blender.Window.RedrawAll()

#scn= Scene.GetCurrent()

#print 'provo a dare due refresh'

#Blender.Window.RedrawAll()

Blender.Set('curframe', 2)
Blender.Window.RedrawAll()

#Blender.Window.DrawProgressBar    
#Blender.Window.QRedrawAll

I think you need to use Redraw(). But I’ve been out of the Python field for some time, may remember wrong.

Anyway, I hope you will continue your line of experiments. Blender really needs a new script to save and load Blender-specific Poses (the old script no longer works past 2.42 :()