From 5d2bb00e2c98be4cac8e6eae7edba9782d710e04 Mon Sep 17 00:00:00 2001 From: n3040 Date: Sun, 24 Jul 2022 17:18:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E8=BF=9E=E7=BB=AD=E6=A1=A3=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E5=81=9A=E6=88=90=E4=B8=80=E4=B8=AA=E7=B1=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 192 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index e32c9c7..8203ef7 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import os import re import numpy as np from time import sleep +from attrs import define # 读取Z文件,找到Z断面第一个点的坐标 def plane_z_origin(z_file_path): @@ -47,11 +48,175 @@ class StringImpactExcel: sheet = wb.sheets["3225-3226"] print(sheet.range("V25:V46").value) -def set_true_color(object,r,g,b): - true_color=object.TrueColor - true_color.SetRGB(r,g,b) -def main(): +def set_true_color(object, r, g, b): + true_color = object.TrueColor + true_color.SetRGB(r, g, b) + object.TrueColor = true_color + + +@define +class ContinuousPlate: + _dwg_file_path: str + _s_file_path: str + _from_tower_name: str + _draw_tower_count: int + + def draw(self, save_to: str): + s_file = SFile() + s_file_path = self._s_file_path + s_file.open(s_file_path) + # with xw.App(visible=False) as app: + # wb_string_impact = app.books.open("特高压耐张串影响弧垂计算(送电室2018人员版)1122-1218.xls") + # stringImpactExcel = StringImpactExcel() + # stringImpactExcel.read(wb_string_impact) + dwg_file_path = self._dwg_file_path + with Apyautocad( + create_if_not_exists=True, visible=False, auto_close=False + ) as cad: + doc = cad.app.Documents.Open(dwg_file_path) + sleep(1) + z_file_path = deduce_zfile_from_cad_path(dwg_file_path) + z_point = plane_z_origin(z_file_path) + fitting_file_path = deduce_fit_db_from_cad_path(dwg_file_path) + fitting = Fitting(fitting_file_path) + fitting_length_dict = fitting.fitting_length_dic + first_tower_point = z_point + last_tower_info = None # 上一个塔位信息 + accu_mileage = 0 # 累计档距 + accu_altitude_off = 0 # 累计高差 + is_first_tower = True + can_start_draw=-1 + start_tower_name=self._from_tower_name + draw_count=0 + for tower in s_file.tower_dic: + tower_info = s_file.tower_dic[tower] + if tower_info.tower_name==start_tower_name: + can_start_draw=0 + if can_start_draw<0 or draw_count>self._draw_tower_count-1: + break + if not last_tower_info: + last_tower_info = tower_info + foundation_low = tower_info.foundation_low + accu_mileage = ( + accu_mileage + + tower_info.mileage_in_s + - last_tower_info.mileage_in_s + ) + accu_altitude_off = accu_altitude_off + tower_info.altitude_off # 中心桩高程 + tower_start = APoint( + *( + ( + first_tower_point + + np.array( + [ + accu_mileage / 5, + (accu_altitude_off - foundation_low) * 2, + ] + ) + ).tolist() + ) + ) + tower_height = tower_info.tower_height + tower_end = APoint( + *( + first_tower_point + + np.array( + [ + accu_mileage / 5, + (accu_altitude_off + tower_height - foundation_low) * 2, + ] + ) + ).tolist() + ) + # 画杆高 + cad.model.AddLine(tower_start, tower_end) + draw_count+=1 + # 画弧垂 + if not is_first_tower: # 从第二基塔开始画 + draw_k = tower_info.back_k + span = tower_info.mileage_in_s - last_tower_info.mileage_in_s + last_tower_fiting = last_tower_info.fitting + last_tower_fitting_length = fitting_length_dict[last_tower_fiting] + if last_tower_info.is_tension_tower: + last_tower_fitting_length = 0 + tower_fitting = tower_info.fitting + tower_fitting_length = fitting_length_dict[tower_fitting] + if tower_info.is_tension_tower: + tower_fitting_length = 0 + last_tower_height = last_tower_info.tower_height + last_foundation_low = last_tower_info.foundation_low + # 挂点高差 + fiting_altitude_off = ( + tower_info.altitude_off + + (tower_height - foundation_low - tower_fitting_length) + - ( + last_tower_height + - last_foundation_low + - last_tower_fitting_length + ) + ) # 前侧高为正 + # 画导线弧垂 + x = np.linspace(0, span, int(span), endpoint=True) + curve = curve_fun(x, span, draw_k, fiting_altitude_off) + draw_curve_x = (first_tower_point[0]) + ( + x + accu_mileage - span + ) / 5 + draw_curve_y = ( + first_tower_point[1] + + ( + +curve + + accu_altitude_off + - tower_info.altitude_off + - last_tower_info.foundation_low + + last_tower_info.tower_height + - last_tower_fitting_length + ) + * 2 + ) + draw_curve_x = draw_curve_x.reshape(len(draw_curve_x), 1) + draw_curve_y = draw_curve_y.reshape(len(draw_curve_y), 1) + draw_ground_curve_y = draw_curve_y - 18 * 2 # 切地线 + draw_tree_curve_y = draw_curve_y - 13.5 * 2 # 切树线 + draw_point = np.hstack( + (draw_curve_x, draw_curve_y, np.zeros((len(draw_curve_x), 1))) + ) + draw_ground_curve_point = np.hstack( + ( + draw_curve_x, + draw_ground_curve_y, + np.zeros((len(draw_curve_x), 1)), + ) + ) + draw_tree_curve_point = np.hstack( + ( + draw_curve_x, + draw_tree_curve_y, + np.zeros((len(draw_curve_x), 1)), + ) + ) + added_curve = cad.model.AddPolyLine( + draw_point.reshape(1, draw_curve_x.shape[0] * 3)[0] + ) + set_true_color(added_curve, 122, 219, 245) + added_ground_curve = cad.model.AddPolyLine( + draw_ground_curve_point.reshape( + 1, draw_ground_curve_y.shape[0] * 3 + )[0] + ) + set_true_color(added_ground_curve, 122, 219, 245) + added_tree_curve = cad.model.AddPolyLine( + draw_tree_curve_point.reshape( + 1, draw_tree_curve_y.shape[0] * 3 + )[0] + ) + set_true_color(added_tree_curve, 116, 230, 165) + is_first_tower = False + last_tower_info = tower_info + doc.SaveAs(save_to) + + +def main1(): # with xw.App(visible=False) as app: # wb = app.books.open('张力计算(临界档距公式法V20090602)-送电室版).xls') # sheet = wb.sheets['2710导线-单回1250-70'] @@ -63,7 +228,7 @@ def main(): # wb_string_impact = app.books.open("特高压耐张串影响弧垂计算(送电室2018人员版)1122-1218.xls") # stringImpactExcel = StringImpactExcel() # stringImpactExcel.read(wb_string_impact) - with Apyautocad(create_if_not_exists=True, visible=False) as cad: + with Apyautocad(create_if_not_exists=True, visible=False, auto_close=False) as cad: doc = cad.app.Documents.Open(r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\033A.dwg") sleep(1) z_file_path = deduce_zfile_from_cad_path( @@ -170,21 +335,35 @@ def main(): draw_tree_curve_point = np.hstack( (draw_curve_x, draw_tree_curve_y, np.zeros((len(draw_curve_x), 1))) ) - added_curve=cad.model.AddPolyLine( + added_curve = cad.model.AddPolyLine( draw_point.reshape(1, draw_curve_x.shape[0] * 3)[0] ) - set_true_color(added_curve,122,219,245) - added_ground_curve=cad.model.AddPolyLine( - draw_ground_curve_point.reshape(1, draw_ground_curve_y.shape[0] * 3)[0] + set_true_color(added_curve, 122, 219, 245) + added_ground_curve = cad.model.AddPolyLine( + draw_ground_curve_point.reshape( + 1, draw_ground_curve_y.shape[0] * 3 + )[0] ) - set_true_color(added_ground_curve,122,219,245) - added_true_curve=cad.model.AddPolyLine( + set_true_color(added_ground_curve, 122, 219, 245) + added_tree_curve = cad.model.AddPolyLine( draw_tree_curve_point.reshape(1, draw_tree_curve_y.shape[0] * 3)[0] ) - set_true_color(added_true_curve, 116, 230, 165) + set_true_color(added_tree_curve, 116, 230, 165) is_first_tower = False last_tower_info = tower_info doc.SaveAs(r"d:\工程\金上线\code\考虑耐张串重弧垂\T033A.dwg") -main() +def main(): + continousePlate = ContinuousPlate( + r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\033A.dwg", + r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\S033.DAT", + "N3339", + 7, + ) + continousePlate.draw(r"d:\工程\金上线\code\考虑耐张串重弧垂\T033A.dwg") + + +if __name__ == "__main__": + main() + print("Finished.")