Text file input

okay everyone, it’s been a while since I programmed in python but I’m working on a project
I’m creating an overlay for my video.
The overlap will be rendered in quicktime with a transparency and then composited on top of the footage.
So what I want to do
1)read and parse a text file, the text file has one of the two following formats on each line:
12345 678 90123
12345 67.8 90123

The file is 592 kbytes and represents 10 minutes of data at 20 frames a second. So constantly loading the file into memory each frame is bad. My final render will be 60 frames a second.

  1. I need to convert two text objects with the two first two respective values, the third value is a timestamp and is throw out

  2. I also need to rotate 2 planes based on the numerical value relative to it’s maximum possible value. For instance, if the max value is 1000 and the supplied value is 500, I want the object to rotate 45 degrees. How to modify a planes rotation and how to modify test.

I hope to use the planes as a mask in the editor. With all this functionality, I hope to generate something to a car dashboard where it displays the speed in text and a gauge.

Any help would be appreciated. I need help learning how to open files. Read the file efficiently without lagging my computer excessively. How to update blender each render cycle. How to create a global “file” object if necessary.

Is it possible to parse it efficiently from the text editor window?

Current Code:

# settings.py

def init():
    global mylist
    global myItr
    myItr = 0
    with open('f:/vid/mylog.txt') as f:
        myList = f.readlines()

# main.py

import settings


def my_handler(scene):
    maxRadians  = 1.5708
    speedMax = 10000
    altitudeMax = 200

    inputLine = settings.mylist[myItr]
    inputList = inputLine.split(" ")
    speedText = inputList[0]
    altitudeText = inputList[1]
    speed = float(speedText)
    altitude = float(altitudeText)

    bpy.data.objects["textSpeed"].data.body = speedText
    bpy.data.objects["planeSpeed"].rotation_euler = (0,0,speed/speedMax*maxRadians)

    bpy.data.objects["textAltitude"].data.body = altitudeText
    bpy.data.objects["planeAltitude"].rotation_euler = (0,0,altitude/maxAltitude*maxRadians)
    settings.myItr = settings.myItr + 1



Is any of this correct?
Can’t figure out how to get current frame number. - worked around
I don’t know where to put the files on my computer. - fixed
I can’t get the settings.py to import - fixed

getting following error: AttributeError: module ’ settings’ has no atribute ‘mylist’ - fixed
okay, got the script to run, now it only displays the first line, it doesn’t iterate.

bpy.context.scene.frame_current will get you the current frame. That will probably help the issue where it only displays the first line.

Honestly reading 592 bytes is nothing. Reading that for 10 minutes of footage at 20 fps may at worst add a few seconds to your render time, so for what you’re doing I wouldn’t worry about that.