Changing Frame in Blender


(ray_theway) #1

I’m working on a script that exports the position of vertices in predefined key frames of a simple animation. Here’s the code:

import Blender
import math
import sys
import os
import string
import array
from Blender import NMesh, Object
from array import array

frame = Blender.Get('curframe')
eframe = Blender.Get('endframe')

object = Object.GetSelected()
objname = object[0].name
meshname = object[0].data.name
mesh = NMesh.GetRaw(meshname)
planefile = open(("D:/Blender/b_.csv"), 'w')
iteration = 0
times = 0
sele = Blender.link
sframes = array('h', [0, 16, 32, 56, 72, 76, 92, 108, 124, 140, 156])
for vertex in mesh.verts:
		iteration = iteration + 1
		planefile.write(',,Number: %s,Section: Brass,
 Set,Step,Left - Right,Visitor - Home,
' % iteration)
		times = 0
		for frame in sframes:
			times = times + 1
			sele = sframes
# the line below
			Blender.Get('curframe') = sele
# the line above
			sele = sframes
			if frame == eframe:
				break

The script continues, but I don’t think there’s a problem with it ('cept that it’s got too many ‘elifs’ to count :slight_smile: ). Well, it seems to get hung up on me trying to tell it what frame to put Blender on. Any ideas?

P.S. I’m pretty sure I have to use the script link buttons in Blender. I just don’t know how.


(eeshlo) #2

You are making things more complex than it needs to be. You don’t need a framechanged scriptlink if you only want to export a subset of frames. Blender also allows you to set the frame, so you could just set the current frame to the frame you are interested in and then export the mesh:


import Blender

# get the first selected object
objects = Blender.Object.GetSelected()
# stop in case nothing is selected
if len(objects)==0:
    raise "No objects selected"
# first object in list, object.data is the mesh, no need to use GetRaw
mesh = objects[0].data
planefile = open(("D:/Blender/b_.csv"), 'w')
sframes = [0, 16, 32, 56, 72, 76, 92, 108, 124, 140, 156]

for frame in sframes:
    # set current frame
    Blender.Set('curframe', frame)
    # redraw, not really needed though,
    # but it helps to see that the frame really changes
    Blender.Redraw()
    #  export the mesh
    for vertex in mesh.verts:
         ...........


(ray_theway) #3

Thanks, eeshlo. I trimmed down the script a little bit and was successful in getting the frame change. The only problem is I’m trying to export vertex keys, which some say is impossible. I’ve heard that povanim exports RVK’s (which I believe are similar to VK’s - course, I can’t be terribly sure) and it uses a compiled python script, so there might be some trick. I pleased for now, at least, that my script outputs nice clean csv’s now. :smiley:


(theeth) #4

If you want to export RVKs (which have only slight differences with VKs, but none that concerns exporting), you’d have to export the mesh data every frame with the Blender.NMesh.GetRawFromObject() function. It works like GetRaw, but exports the deformations.

Martin


(jms) #5

The povanim’s method is explained there:
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_rawfromobject.htm

jm