改用cad而非第三方库生成dwg
This commit is contained in:
parent
363a14e98b
commit
1387aa277e
|
|
@ -0,0 +1,24 @@
|
||||||
|
from typing import List
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def convert_dxf_to_dwg(dxf_files: List[str]):
|
||||||
|
cad_file_path = r"D:/Program Files/Cad2022/AutoCAD 2022/acad.exe"
|
||||||
|
first_dwg_file = dxf_files[0]
|
||||||
|
dir_path = os.path.dirname(first_dwg_file)
|
||||||
|
script_path = f"{dir_path}/batch.scr"
|
||||||
|
with open(script_path, "w", encoding="ansi") as f:
|
||||||
|
for dxf in dxf_files:
|
||||||
|
f.write("FILEDIA 0\n")
|
||||||
|
f.write(f'_open "{dxf}"\n')
|
||||||
|
file_name_path, _ = os.path.splitext(dxf)
|
||||||
|
new_dwg_name = f'{file_name_path}.dwg'
|
||||||
|
if os.path.exists(new_dwg_name):
|
||||||
|
os.remove(new_dwg_name)
|
||||||
|
f.write(f'saveas 2004 "{new_dwg_name}"\n')
|
||||||
|
f.write("FILEDIA 1\n")
|
||||||
|
f.write(f"_close\n")
|
||||||
|
f.write("_exit ")
|
||||||
|
cmd = rf'"{cad_file_path}" /b "{script_path}"'
|
||||||
|
subprocess.Popen(cmd)
|
||||||
29
dem.py
29
dem.py
|
|
@ -9,6 +9,7 @@ import pandas as pd
|
||||||
from pw import DFile, ControlFile
|
from pw import DFile, ControlFile
|
||||||
import dem_utils
|
import dem_utils
|
||||||
from nwed import Nwed
|
from nwed import Nwed
|
||||||
|
import cad
|
||||||
|
|
||||||
|
|
||||||
class Dem:
|
class Dem:
|
||||||
|
|
@ -48,6 +49,7 @@ class Dem:
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
# TODO:不应该设置缩放因数
|
# TODO:不应该设置缩放因数
|
||||||
|
dxfs=[]
|
||||||
zoom_factor = 1
|
zoom_factor = 1
|
||||||
excel_pfs = self._read_path_file()
|
excel_pfs = self._read_path_file()
|
||||||
segments = []
|
segments = []
|
||||||
|
|
@ -178,11 +180,13 @@ class Dem:
|
||||||
)
|
)
|
||||||
from ezdxf.addons.odafc import export_dwg
|
from ezdxf.addons.odafc import export_dwg
|
||||||
|
|
||||||
export_dwg(
|
# export_dwg(
|
||||||
dm_doc,
|
# dm_doc,
|
||||||
f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dwg",
|
# f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dwg",
|
||||||
replace=True,
|
# replace=True,
|
||||||
) # 写断面文件
|
# ) # 写断面文件
|
||||||
|
dm_doc.saveas(f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dxf",)
|
||||||
|
dxfs.append(f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dxf")
|
||||||
# 写Z文件
|
# 写Z文件
|
||||||
z_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
|
z_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
|
||||||
with open(z_file_path, "w") as z_file:
|
with open(z_file_path, "w") as z_file:
|
||||||
|
|
@ -266,13 +270,18 @@ class Dem:
|
||||||
f"{out_dxf_file_dir}/{100+int(start_point_name[1:])}.nwed",
|
f"{out_dxf_file_dir}/{100+int(start_point_name[1:])}.nwed",
|
||||||
)
|
)
|
||||||
# 写整个断面文件
|
# 写整个断面文件
|
||||||
export_dwg(
|
# export_dwg(
|
||||||
dm_whole_doc,
|
# dm_whole_doc,
|
||||||
f"{out_dxf_file_dir}/DA.dwg",
|
# f"{out_dxf_file_dir}/DA.dwg",
|
||||||
replace=True,
|
# replace=True,
|
||||||
)
|
# )
|
||||||
|
dm_whole_doc.saveas(f"{out_dxf_file_dir}/DA.dxf")
|
||||||
|
# cad.convert_dxf_to_dwg([f"{out_dxf_file_dir}/DA.dxf"])
|
||||||
|
dxfs.append(f"{out_dxf_file_dir}/DA.dxf")
|
||||||
# 写平面文件
|
# 写平面文件
|
||||||
plate_doc.saveas(f"{out_dxf_file_dir}/plate.dxf")
|
plate_doc.saveas(f"{out_dxf_file_dir}/plate.dxf")
|
||||||
|
dxfs.append(f"{out_dxf_file_dir}/plate.dxf")
|
||||||
|
cad.convert_dxf_to_dwg(dxf_files=dxfs)
|
||||||
|
|
||||||
def get_elevation(self, site_x_y):
|
def get_elevation(self, site_x_y):
|
||||||
"""Get the elevation of given locations from DEM in GCS.
|
"""Get the elevation of given locations from DEM in GCS.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue