Hello again all! (and happy easter if you are that way inclined)
I have this file called cameratrack.txt :
And basically it is frame numbers and co-ordinates for a 3d object animation. I need to put each line's data into 4 different lists, which are frame, cordx, cordy and cordz. So for example line 2 would be frame[5], cordx[5], cordy[0], cordz[0]. I've got a solution with the following code:
but was wondering if I've gone round a long way of doing this? I've got the string joining from this thread:
http://www.thescripts. com/forum/threadnav621769-2-10.html
but was wondering if anyone could see an obvious improvement on the code that Im missing? Any help would be appreciated, if not no worries!
Thanks!
Mel
I have this file called cameratrack.txt :
Code:
0 (0 ,0 ,0 ) 5 (5 ,0 ,0 ) 10 (10 ,0 ,0 ) 15 (15 ,5 ,0 ) 20 (20 ,10 ,0 ) 25 (25 ,15 ,0 ) 30 (30 ,20 ,5 ) 35 (30 ,25 ,10 ) 40 (30 ,30 ,15 ) 45 (30 ,30 ,20 ) 50 (30 ,30 ,25 )
Code:
#######camera tracking##########
import string
frame = [] # The frame number of animation
cordx = [] # The x position of object
cordy = [] # The y position of object
cordz = [] # The z position of object
f = open('C:\rest of filepath\cameratrack.txt', 'r')
data = f.readlines() # Reading of the file
datalength = len(data[0]) # Length of each line
filelength = len(data) # Length of file
print data
print datalength
print filelength
i = 0
while i != filelength:
frameppoints = [data[i][0], data[i][1], data[i][2]]
framenum= float(string.join(frameppoints,'')) # Join to make frame number
frame.insert(i,framenum) # num inserted into list
xpoints = [data[i][4], data[i][5], data[i][6]]
xcords = float(string.join(xpoints,''))
cordx.insert(i,xcords)
ypoints = [data[i][8],data[i][9], data[i][10]]
ycords = float(string.join(ypoints,''))
cordy.insert(i,ycords)
zpoints = [data[i][12], data[i][13],data[i][14]]
zcords = float(string.join(zpoints,''))
cordz.insert(i,zcords)
i+=1
print frame
print cordx
print cordy
print cordz
http://www.thescripts. com/forum/threadnav621769-2-10.html
but was wondering if anyone could see an obvious improvement on the code that Im missing? Any help would be appreciated, if not no worries!
Thanks!
Mel
Comment