I’ve started working on a python script that reads a list of coordinates from a file formatted like the .dat files found
here (http://www.ae.illinois.edu/m-selig/ads/coord_database.html. A sample of this format is below. This is the B29root.dat file.
B-29 ROOT AIRFOIL
19.0 21.0
0.0000000 0.0000000
0.0082707 0.0233088
0.0132000 0.0298517
0.0255597 0.0425630
0.0503554 0.0603942
0.0751941 0.0739301
0.1000570 0.0850687
0.1498328 0.1023515
0.1996558 0.1149395
0.2495240 0.1230325
0.2994312 0.1272298
0.3993490 0.1253360
0.4993711 0.1130538
0.5994664 0.0934796
0.6996058 0.0695104
0.7997553 0.0445423
0.8998927 0.0207728
0.9499514 0.0098870
1.0000000 0.0000000
0.0000000 0.0000000
0.0061140 -.0208973
0.0062188 -.0210669
0.0087532 -.0247377
0.0138088 -.0307807
0.0264052 -.0416431
0.0515127 -.0548774
0.0765762 -.0637165
0.1016176 -.0703581
0.1516652 -.0801452
0.2016828 -.0869356
0.2516733 -.0910290
0.3016387 -.0926252
0.4015163 -.0905235
0.5013438 -.0834273
0.6011363 -.0728351
0.7008976 -.0591463
0.8006328 -.0428603
0.9003380 -.0235778
0.9501740 -.0122883
1.0000000 0.0000000
As far as I know, the coordinates in the left column are the “x” coords and the right column is the “y” coord.
Here is an example of a proof of concept piece of code that I found on the blender 2.48 API that draws vertices:
from Blender import *
import bpy
editmode = Window.EditMode() # are we in edit mode? If so ...
if editmode: Window.EditMode(0) # leave edit mode before getting the mesh
# define vertices and faces for a pyramid
coords=[ [-1,-1,-1], [1,-1,-1], [1,1,-1], [-1,1,-1], [0,0,1] ]
faces= [ [3,2,1,0], [0,1,4], [1,2,4], [2,3,4], [3,0,4] ]
me = bpy.data.meshes.new('myMesh') # create a new mesh
me.verts.extend(coords) # add vertices to mesh
me.faces.extend(faces) # add faces to the mesh (also adds edges)
me.vertexColors = 1 # enable vertex colors
me.faces[1].col[0].r = 255 # make each vertex a different color
me.faces[1].col[1].g = 255
me.faces[1].col[2].b = 255
scn = bpy.data.scenes.active # link object to current scene
ob = scn.objects.new(me, 'myObj')
if editmode: Window.EditMode(1) # optional, just being nice
That obviously would have to be heavily changed, but it does show that it is possible.
The code I have for reading the file is below. It works almost perfectly in python (Fedora 11, python 2.6.2). It just says that line0 cannot be found and raises an exception after printing out everything.
f = open('b29root.txt', 'r')
lineno = 1
strline = ""
vartxt = "line"
for line in f:
strline = str(lineno)
vars()[vartxt + strline] = line
lineno += 1
while lineno != 0:
lineno -= 1
print lineno
printvar = "print line%i" % (lineno)
exec printvar
I tried putting this code into blender, and it hates me. It raises an exception at the same place, but it doesn’t print anything. I even tried (:P) putting a “try” and “except” for the “exec printvar” but while that stops it having an error message, it only prints out a 0.
What can I do to fix this?