.DAT to .DXF Converter

작성자

카테고리:

← 피드로
DEV Community · Spondon Saha · 2026-07-21 개발(SW)
Cover image for .DAT to .DXF Converter

Spondon Saha

NACA 2412 Airfoil Databases are in .dat file. The problem? There are no clean .dat -> .dxf converters. The solution? I built one.

This post is directly linked to my ongoing project at the time of writing: Comparative Aerodynamic Analysis Of Wing Planforms.

I needed to model a NACA 2412 wing which had .dat coordinate files available. But OnShape needed .dxf in order to import the coordinates. I couldn’t find a clean converter online, so I decided to build one for the sake of this project. I wanted to share the script:

#plot_airfoil.py
# Desired chord length (mm)
CHORD = 200
# import necessary libraries for dxf conversion
import ezdxf
# Path to airfoil data file
import os
script_dir = os.path.dirname(os.path.abspath(__file__))
filename = os.path.join(script_dir, "..", "airfoil", "naca2412.dat")
#Open the file
with open(filename, 'r') as file:
    lines = file.readlines()
#Print every line
#for line in lines:
 #   print(line)
import matplotlib.pyplot as plt
x = []
y = []
with open(filename, 'r') as file:
    lines = file.readlines()
for line in lines[1:]: #Skip the NACA 2412 header line
    values = line.split()
    if len(values) == 2:
        x_coord = float(values[0]) * CHORD
        y_coord = float(values[1]) * CHORD
        x.append(float(x_coord))
        y.append(float(y_coord))
plt.figure(figsize=(8, 3))
plt.plot(x, y)

plt.axis("equal")
plt.grid(True)

plt.xlabel("x")
plt.ylabel("y")
plt.title("NACA 2412 Airfoil")

#plt.show()
# Remove the hashtag from the line above to plot the airfoil. The line is commented out to avoid opening a plot window when running the script in a non-interactive environment.
# ---
# Export airfoil to dxf file
CHORD = 200.0 #mm
#Scale coordinates to desired chord length
scaled_x = x
scaled_y = y

doc = ezdxf.new()
msp = doc.modelspace()
#Add polyline
msp.add_lwpolyline(list(zip(scaled_x, scaled_y)), close=True)
#Save file
script_dir = os.path.dirname(os.path.abspath(__file__))
output_file = os.path.join(script_dir, "..", "cad", "naca2412_200mm.dxf")

doc.saveas(output_file)

print(f"Saved to: {output_file}")

Enter fullscreen mode Exit fullscreen mode

The paths & directories in the code was based on my own folder structure, so do feel free to change it as per your requirement if you do plan on using it! It is also available on the GitHub repository mentioned above.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다