#!BPY """ Name: 'Airfoil data...' Blender: 241 Group: 'Import' Tooltip: 'Import airfoil data in selig file format (*.dat), http://www.aae.uiuc.edu/m-selig/ads/coord_database.html' """ __author__ = "Wim Van Hoydonck" __version__ = "0.1" __bpydoc__ = """\ This script imports airfoil coordinate files into Blender. Airfoil databases can be found here: http://www.aae.uiuc.edu/m-selig/ads/coord_database.html and here: http://mitglied.lycos.de/frankranis/ Usage: Run the script from "File->Import" and select the desired DAT file """ ####################################################################### # # # import airfoil coordinate-files (*.dat) # # as found on http://www.aae.uiuc.edu/m-selig/ads/coord_database.html # # and http://mitglied.lycos.de/frankranis/ # # # # (C) 2006 Wim Van Hoydonck # # email: wim.van.hoydonck@nospam.gmail.nospam.com # # # # Released under the GNU GPL v2.0 # # # # Take a look overhere: # # http://www.aai.uiuc.edu/m-selig/ads/aircraft.html # # # # NOTE: # # Some files at http://www.aae.uiuc.edu/m-selig/ contain # # irregularities, check the terminal for more info if the airfoil # # seems to be missing some vertices. # # # ####################################################################### import Blender from Blender import Mesh, Mathutils, Object, Scene from math import fmod import string, sys def read(filename): file = open(filename, "rb") lines = file.readlines() length = len(lines)-1 objname = Blender.sys.splitext(Blender.sys.basename(filename))[0] print "" print "importing", objname # irregularities irreg = 0 zfirst = -10.0 # initiate coordinate lists coo_list = [] for i in range(1,length+1): line = lines[i] # strip line from too many whitespaces # split line in two # make strings float try: x, z = map(float, string.split(string.strip(line))) y = 0 coo_list.append([x,y,z]) except ValueError: print "Line", i+1, "contains irregularities, check the file" irreg +=1 # create new mesh with the coordinate list new_mesh(coo_list,objname) def new_mesh(coo_list,objname): # the new mesh and object m = Mesh.New() obj = Object.New('Mesh') # add vertices to mesh for i in range(0,len(coo_list)): m.verts.extend(Mathutils.Vector(coo_list[i])) # construct edges with the verts for i in range(0,len(m.verts)): m.edges.extend(m.verts[i],m.verts[int(fmod(i+1,len(m.verts)))]) # give it some names m.name = objname obj.name = objname # link object to mesh obj.link(m) # get current scene and link object to this scene scene1 = Scene.GetCurrent() scene1.link(obj) Blender.Redraw() def fs_callback(filename): read(filename) Blender.Window.FileSelector(fs_callback, "airfoil coordinate import")