2

I've used a script to extract my bones location to a text file and I was wondering if I could use this text file to import the locations to a new project in blender using another script.

Keep in mind that I literally have no knowledge of Python (I found the script that I've used to export the bone locations from another place and kind of modified it to suit my needs) and I'm very new to blender as well and was hoping if someone could help me out here.

Here's the text file I mentioned:

Current Frame 0
Bone000: HeadX:-0.0 HeadY:-0.0 HeadZ:0.0 TailX:-0.0 TailY:0.10000000149011612 TailZ:0.0
Bone001: HeadX:-0.0 HeadY:-0.0 HeadZ:1.2218284606933594 TailX:-0.0 TailY:0.10000000149011612 TailZ:1.2218284606933594
...
Bone140: HeadX:-0.0 HeadY:-0.0 HeadZ:0.0 TailX:-0.0 TailY:0.10000000149011612 TailZ:0.0

This is where I found the script:

https://blenderartists.org/t/save-bone-position-and-rotation-in-a-txt-file/1219916

this is what I changed it to:

import bpy

start_frame = 0 scene = bpy.data.scenes["Scene"] armature = scene.objects["Armature"] outputfile = bpy.path.abspath("C:\Bones.txt")

pose_list = [] rota_list = [] buffer = []

def export_bone(bone): pos0 = bone.head pos1 = bone.tail # log and append to buffer msg = "{0}: HeadX:{1} HeadY:{2} HeadZ:{3} TailX:{4} TailY:{5} TailZ:{6}".format(bone.name, pos0.x, pos0.y, pos0.z, pos1.x, pos1.y, pos1.z) print(msg) buffer.append(msg)

loop all frames

print("Starting Export") scene.frame_current = start_frame while scene.frame_current < scene.frame_end: # log and append to buffer msg = "Current Frame {0}".format(scene.frame_current) print(msg) buffer.append(msg)

# change frame
scene.frame_current += 0

# export all bones of armature
for bone in armature.pose.bones:
    export_bone(bone)

output buffer to file

with open(outputfile, "w") as f: f.write("\n".join(buffer))'

Any help would be much appreciated Cheers

  • 1
    Related: https://blender.stackexchange.com/questions/80230/how-to-make-blender-use-text-file-as-an-input-of-bones-animation – brockmann Oct 30 '20 at 13:02
  • hey thx for replying. yes I saw this but my problem was that the original text that the user posted which led to the answer is gone and I have no way of knowing what format it was. and as i stated earlier I have very little knowledge of python and can't understand the answer provided... – Mani Tabibzadeh Oct 30 '20 at 13:43
  • yes of course. edited to original post with the added info – Mani Tabibzadeh Oct 31 '20 at 22:50
  • Recommend, setting frame = start_frame testing with frame < scene.frame_end, changing frame with scene.frame_set(frame) and incrementing with frame += 1 – batFINGER Nov 01 '20 at 01:36
  • Could you please elaborate on what your needs are. The bvh import / export creates a text file with both the rig and animation. The link posted is outputting the animation per frame. You have edited to export only the head and tail locations of each bone per frame in the animation. – batFINGER Nov 01 '20 at 04:00

0 Answers0