Compare commits

..

2 Commits

Author SHA1 Message Date
n3040
0665a83a9c dxf需要输出R2010以后版本,否则cad打开出错。 2024-06-29 01:16:10 +08:00
n3040
d7e16069db 修复了autocad不能识别//路径的bug。 2024-02-22 19:54:28 +08:00
2 changed files with 17 additions and 6 deletions

10
cad.py
View File

@@ -3,7 +3,6 @@ import os
import subprocess import subprocess
def convert_dxf_to_dwg(dxf_files: List[str]): def convert_dxf_to_dwg(dxf_files: List[str]):
cad_file_path = r"D:/Program Files/Cad2022/AutoCAD 2022/accoreconsole.exe" cad_file_path = r"D:/Program Files/Cad2022/AutoCAD 2022/accoreconsole.exe"
first_dwg_file = dxf_files[0] first_dwg_file = dxf_files[0]
@@ -15,9 +14,16 @@ def convert_dxf_to_dwg(dxf_files: List[str]):
new_dwg_name = f"{file_name_path}.dwg" new_dwg_name = f"{file_name_path}.dwg"
if os.path.exists(new_dwg_name): if os.path.exists(new_dwg_name):
os.remove(new_dwg_name) os.remove(new_dwg_name)
new_dwg_name = new_dwg_name.replace("//", "/")
f.write(f'saveas 2004 "{new_dwg_name}"\n') f.write(f'saveas 2004 "{new_dwg_name}"\n')
cmd = rf'"{cad_file_path}" /s "{script_path}" /i "{dxf}" /iso' cmd = rf'"{cad_file_path}" /s "{script_path}" /i "{dxf}" /iso'
subprocess.call(cmd,stderr=subprocess.DEVNULL,stdin=subprocess.DEVNULL,stdout=subprocess.DEVNULL) cmd = cmd.replace("//", "/")
subprocess.call(
cmd,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
)
def convert_dxf_to_dwg1(dxf_files: List[str]): def convert_dxf_to_dwg1(dxf_files: List[str]):

13
dem.py
View File

@@ -58,7 +58,7 @@ class Dem:
toml_dict = self._toml_dict toml_dict = self._toml_dict
out_dxf_file_dir = toml_dict["parameter"]["out_dxf_file_dir"] out_dxf_file_dir = toml_dict["parameter"]["out_dxf_file_dir"]
# 写整个断面 # 写整个断面
dm_whole_doc = ezdxf.new(dxfversion="R2004") dm_whole_doc = ezdxf.new(dxfversion="R2010")
dm_whole_accumulative_distance = 0 # 累加里程 dm_whole_accumulative_distance = 0 # 累加里程
dm_whole_msp = dm_whole_doc.modelspace() dm_whole_msp = dm_whole_doc.modelspace()
for foo in range(len(excel_pfs) - 1): for foo in range(len(excel_pfs) - 1):
@@ -74,7 +74,7 @@ class Dem:
left_elevation = self.get_elevation(line_coordination[:, 0:2]) left_elevation = self.get_elevation(line_coordination[:, 0:2])
center_elevation = self.get_elevation(line_coordination[:, 2:4]) center_elevation = self.get_elevation(line_coordination[:, 2:4])
right_elevation = self.get_elevation(line_coordination[:, 4:6]) right_elevation = self.get_elevation(line_coordination[:, 4:6])
dm_doc = ezdxf.new(dxfversion="R2004") dm_doc = ezdxf.new(dxfversion="R2010")
# 设置线形 # 设置线形
# for name, desc, pattern in linetypes(): # for name, desc, pattern in linetypes():
# if name not in dm_doc.linetypes: # if name not in dm_doc.linetypes:
@@ -93,6 +93,8 @@ class Dem:
(x_axis[i] / 5 / zoom_factor, left_elevation[i] * 2 / zoom_factor) (x_axis[i] / 5 / zoom_factor, left_elevation[i] * 2 / zoom_factor)
for i in range(len(left_elevation)) for i in range(len(left_elevation))
] ]
# dm_whole_msp.add_polyline2d([[0,0],[100,100]])
# dm_doc.saveas('f.dxf')
dm_whole_msp.add_polyline2d( dm_whole_msp.add_polyline2d(
np.array(left_line) np.array(left_line)
+ np.hstack( + np.hstack(
@@ -378,7 +380,8 @@ class Dem:
path_length = ( path_length = (
(point_x_s - point_x_e) ** 2 + (point_y_s - point_y_e) ** 2 (point_x_s - point_x_e) ** 2 + (point_y_s - point_y_e) ** 2
) ** 0.5 ) ** 0.5
dem_resolution = self._dem_resolution # dem的精度 # dem_resolution = self._dem_resolution # dem的精度
dem_resolution = 5
# TODO:设定为5m 1个点。 # TODO:设定为5m 1个点。
n = round(path_length / dem_resolution) n = round(path_length / dem_resolution)
# n = round(path_length / 5) # n = round(path_length / 5)
@@ -397,7 +400,9 @@ class Dem:
left_offset_y = side_width * math.sin(line_angel + math.pi / 2) left_offset_y = side_width * math.sin(line_angel + math.pi / 2)
left_offset_point_x = center_point_x + left_offset_x left_offset_point_x = center_point_x + left_offset_x
left_offset_point_y = center_point_y + left_offset_y left_offset_point_y = center_point_y + left_offset_y
right_offset_point_x = center_point_x - left_offset_x # 向左偏移和向右偏移正好是相反的 right_offset_point_x = (
center_point_x - left_offset_x
) # 向左偏移和向右偏移正好是相反的
right_offset_point_y = center_point_y - left_offset_y right_offset_point_y = center_point_y - left_offset_y
r = np.array( r = np.array(
[ [