#DXF to DAT generator x = [] y = [] z = [] max_point_spacing = .04 import dxfgrabber as dxf import matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np file = dxf.readfile("Finocyl Mandrel Quarter.DXF") #previous_end_x = #beginning_x = #current_end_x = #previous_end_y = #beginning_y = #current_end_y = count = 0 #reverse_list = [0,3,4,5,6,7,8,10] #star mandrel 1 reverse_list = [4, 9, 10, 12] #finocyl quarter skip_list = [] for i in reversed(file.entities): print(count) if count in skip_list: print(count) elif i.dxftype == "LINE" and count in reverse_list: print("drew line with start{} and end{}".format(i.end, i.start)) start_point = i.end end_point = i.start delta_x = end_point[0]-start_point[0] delta_y = end_point[1]-start_point[1] length = (delta_x**2+delta_y**2)**.5 num_points = int(length/max_point_spacing) for point in range(num_points): x.append(start_point[0]+point*(delta_x/num_points)) y.append(start_point[1]+point*(delta_y/num_points)) elif i.dxftype == "ARC" and count in reverse_list: print("drew arc with start ({},{}) and end ({},{})".format(round(radius*np.cos(np.deg2rad(i.start_angle)),2),round(radius*np.sin(np.deg2rad(i.start_angle)),2),round(radius*np.cos(np.deg2rad(i.end_angle)),2),round(radius*np.sin(np.deg2rad(i.end_angle)),2))) center = i.center radius = i.radius start_angle = i.end_angle end_angle = i.start_angle angle_delta = start_angle-end_angle circumfrence = 2*np.pi*radius*(abs(angle_delta)/360.0) num_points = int(circumfrence/max_point_spacing) for theta in range(num_points): x.append(radius*np.cos(np.deg2rad(end_angle+(angle_delta/num_points)*theta))) #this seems fishy, why end angle? y.append(radius*np.sin(np.deg2rad(end_angle+(angle_delta/num_points)*theta))) elif i.dxftype == "LINE": print("drew line with start{} and end{}".format(i.start, i.end)) start_point = i.start end_point = i.end delta_x = end_point[0]-start_point[0] delta_y = end_point[1]-start_point[1] length = (delta_x**2+delta_y**2)**.5 num_points = int(length/max_point_spacing) for point in range(num_points): x.append(start_point[0]+point*(delta_x/num_points)) y.append(start_point[1]+point*(delta_y/num_points)) elif i.dxftype == "CIRCLE": center = i.center radius = i.radius circumfrence = 2*np.pi*radius num_points = circumfrence/max_point_spacing #for theta in range(int(num_points)): # x.append(radius*np.cos(theta*2*np.pi/num_points)) # y.append(radius*np.sin(theta*2*np.pi/num_points)) elif i.dxftype == "ARC": center = i.center radius = i.radius start_angle = i.start_angle end_angle = i.end_angle angle_delta = start_angle-end_angle circumfrence = 2*np.pi*radius*(abs(angle_delta)/360.0) num_points = int(circumfrence/max_point_spacing) for theta in range(num_points): x.append(radius*np.cos(np.deg2rad(end_angle+(angle_delta/num_points)*theta))) y.append(radius*np.sin(np.deg2rad(end_angle+(angle_delta/num_points)*theta))) print("drew arc with start ({},{}) and end ({},{})".format(round(radius*np.cos(np.deg2rad(i.end_angle)),2),round(radius*np.sin(np.deg2rad(i.end_angle)),2),round(radius*np.cos(np.deg2rad(i.start_angle)),2),round(radius*np.sin(np.deg2rad(i.start_angle)),2))) count += 1 x = np.add(x, 1.9) y = np.multiply(y, -1) y = np.add(y, 1.4) with open("core.dat", 'w') as file: for point in range(len(x)-1): file.write("{} {}\n".format(x[point],y[point])) print("DAT File written for core. It contains {} point pairs".format(len(x))) plt.plot(x,y) plt.axis('equal') plt.show() #fig, ax = plt.subplots() #line, = ax.plot(x, y) def update(num, x, y, line): line.set_data(x[:num], y[:num]) line.axes.axis([0, 3.5, 0, 2.5]) return line, #ani = animation.FuncAnimation(fig, update, len(x), fargs=[x, y, line], ##ani.save('core_cut1.gif') #plt.show()