Airfoil Plotter

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?

Is that all of your code? I don’t even see “line0” used, so obviously something is iuncorrect. I do see “lineo” used, maybe your trying to use line0 when lineo was defined? If not, please post all of your code.

I’m not exactly sure what you want to do with the fact that the file is split into two segments, but if you ignore that this will work for you:

f = open('b29root.txt', 'r')

# read 1st two lines of junk
f.readline()
f.readline()

file_input = f.read().strip().split('
')

for line in file_input:
    line = line.strip().split() # break up each line into two segments

    # convert floats into numbers
    line[0] = float(line[0])
    line[1] = float(line[1])

    # now do something with numbers here
    print line

f.close()

It’s all in the string interpolation and exec statement as well as the vars(). Basically it creates a new variable for each line and the exec part tries to print each line. Most of the variables are created on the fly.

J09:
With the file formatting, when i got it mostly working, i was just going to go into leafpad and delete the unnecessary lines. Since there is 2 of each, I was just going to use string slices, because the f.line gives me a string (doesn’t it?)

You’ve given me a good idea, place the vertices in the for loop. That would probably work better. That way, I wouldn’t need to give each point different names, it could just get overridden each loop. I think i’ll try that.

However, I don’t get

file_input = f.read().strip().split('
')

Does that just get rid of the unnecessary formatting?

can someone explain if there a way to get the file from the currant folder inwhcih the blend file is located

causer right now seems you avhe to place this file in root of C in windows

it would be easier to place files together in same folder if possible

Thanks

O.K.

f.readline() will give you a string containing the entire contents of a single line in the file (including the ’
’ character). However, using “f.readlines()” to get data from the file would require you to run this command for each line in the file (which is unknown). It is easier to simply read in the entire file at once (using “f.read()”) and then split it up.

It’s a number of commands all stuck together. Let me break it up:

f.read()

Reads in the entire file (starting at the cursor location) and puts it into a really long string.

f.read().strip()

Removes spaces and endlines from the ends of the long string. This ensures that if there is an extra (blank) line at the end of the file, it will be excluded from the list of points.

f.read().strip().split('
')

Adding the command split(’
') converts the previous string into a list (array) by splitting the string on each endline.

Then the code enters the loop.

line.strip().split()

Breaks up each line along the central space (using split()) after removing excess whitespace (using strip()). The points can now be easily converted to numbers and used to place verticies.

Oh, oops. Thanks for clarifying. I didn’t read the script closely enough.

Hello. Well, J09, i’ve almost completely ignored what you said. The only thing I took out was that can plot each vertice during the loop that it is read. No exec or vars() needed!

Now the problem is that it’s not reading the file in. So you can see the code and stuff, as well.

http://fake.yolasite.com/resources/blender/scripts/airfoilPlotter/plotter.blend

except i cant’ upload the file at the moment. lemme submit and then we’ll see.

I got it working. Now i’m just creating a page for it on my website,
http://fake.yolasite.com/airfoilplotter.php

The direct download is
http://fake.yolasite.com/resources/blender/scripts/airfoilPlotter/plotter.zip

is this used to trace the shape of a wing in 3D in blender?
would be interesting and usefull to make airplane?

i tried to run the last blend fifle and get an error when reading the file

anybody else has this error ?

Thanks

Yeah, it’s used to trace the airfoil of a wing. The B-29 probably isn’t a good example because the profile changes over the wing (seperate tip and root airfoil). I just hope it changes linearly.

I think it would be somewhat useful for making an aeroplane.

i believe the error either has to do with the version of python you’re using or the version of blender you’re using. It works perfectly on one of my boxes, which runs windows 7 release candidate, blender 2.49 and python 2.6.2. However, it does not work on my fedora 11 box, which runs python 2.6 and blender 2.49.2

So the problem is probably there. I’m going to update the website and point to this thread as the FAQ/help as I don’t think it’s a big enough script to worry about using a whole nother forum.

that’s very good for people who like to make airplane
if your program can do the wings shape it’s already good

but does your program read and drwa the sahpe of ther wing in blender?

that’s definitively a good tool

thanks

Updated so that it creates edges. Also creates one edge down the middle, but that is easy to delete. Easier than adding all the edges yourself.

@RickyBlender
Yeah, it does read a pre-determined wing shape (which is determined through coordinates) and draws it

After trying to find my page on this by googling it (no luck so far, just finding this thread) I also found
http://blenderartists.org/forum/showthread.php?t=9521

However, I believe my script is simpler, and the first one doesn’t work at all for me.

well i got the latest 2.49 with the right python for it

so i guess that it should work

is there anythng that can be change in the file to make it work as yours?

Thanks

Hang on, I just realised in the blender console, it says i’m using python 2.5.2 (I have both installed). I"m going to download the latest version of blender (I have slightly old version) and try from there.

I am really sorry. It appears I worked in the wrong file, and as such the new line functionality completely doesn’t exist. On the plus side, to read the file, you just need to use an absolute path. I think it’s a python 2.6.2 or blender 2.49.2 peculiarity.

I/'m sorry, but i still haven’t uploaded the right versoin that makes the lines for you. Thats a job for the weekend.

Well, i meant to say for “a” weekend. It should be done now.

Hi Fake, any plans to make it 2.5a compatible?

Love.

Gabriel.

No real plans to make it 2.5a compatible at the moment. When i start using 2.5xxx or above, it’ll definitely make the transition. However, i haven’t really blended much lately, and i definitely haven’t started using 2.5a. I should, but i’ll live. I do have 2.5a on my machine, but only to open the durian files.

Thanks for your interest. BTW, the site is now moved to http://jak-o-shadows.users.sourceforge.net The old links still work, but i’m moving over to the new site.