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
frame = start_frametesting withframe < scene.frame_end, changing frame withscene.frame_set(frame)and incrementing withframe += 1– batFINGER Nov 01 '20 at 01:36