1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
from pyautocad import APoint, Autocad, aDouble import win32com.client import numpy as np """ 设计高程:(2)1654.0m 填土边坡与路堑边坡坡率:(1)填方上部1:1.2(高度≤8m),填方下部1:1.4(高度≤12m) ;挖方1:0.9(高度≤20m) 路基宽度:(2) 路面宽7.0米,硬路肩宽0.75米,土路肩宽0.75米 以下数据单位:m """ design_height = 1654.0 slop_fill_up = 1.2 slop_fill_down = 1.4 slop_cut = 0.9 surface_width = 7.0 hard_shoulder = 0.75 dirt_shoulder = 0.75
ctfs = 10 distance_sections = 60
xlapp = win32com.client.Dispatch("Excel.Application") wb = xlapp.ActiveWorkbook ws = xlapp.ActiveWorkbook.ActiveSheet
ground_points = [] row = 2 while row <= 20: i = 6 j = 8
x0 = 0 + (distance_sections * (row - 2))//3 y0 = ws.cells(row, 7).value p0 = APoint(x0, y0) pts = [] pts.append(p0)
while i >= 1: try: y_ = ws.cells(row, i).value x_ = - ws.cells(row + 1, i).value pti = pts[0] + (x_, y_, 0) pts.insert(0, pti) except: pass i -= 1 while ws.cells(row, j).value: y_ = ws.cells(row, j).value x_ = ws.cells(row + 1, j).value ptj = pts[-1] + (x_, y_, 0) pts.append(ptj) j += 1 ground_points.append(pts)
for i in pts: print(i) print("") row = row + 3
acad = Autocad(create_if_not_exists=True) acad.prompt("connect with the Autocad successfully.") print("connect with the Autocad successfully.")
dwg = acad.ActiveDocument "原始地面线"
ysdmx = acad.doc.layers.add("原始地面线") ysdmx.color = 7 ysdmx.LineWeight = 25 dwg.ActiveLayer = ysdmx
for line_pts in ground_points: pt = aDouble([j for i in line_pts for j in i * ctfs]) acad.model.AddPolyLine(pt).LineWeight = 25
"路基线"
orginal_middl_pts = [] pt0 = APoint(0, design_height) orginal_middl_pts.append(pt0) rightpts = [(surface_width/2, 0), (hard_shoulder, 0), (dirt_shoulder, 0), (0.6, - 0.6), (0.6, 0), (0.6, 0.6), (1, 0), (20 * slop_cut, 20)] leftpts = [(surface_width/2, 0), (hard_shoulder, 0), (dirt_shoulder, 0), (8 * slop_fill_up, 8), (2, 0), (12 * slop_fill_down, 12)]
for i in leftpts: pti = orginal_middl_pts[0] - (i[0], i[1], 0) orginal_middl_pts.insert(0, pti) for j in rightpts: ptj = orginal_middl_pts[-1] + (j[0], j[1], 0) orginal_middl_pts.append(ptj)
ljx = acad.doc.layers.add("路基线") ljx.color = 1 ljx.LineWeight = 100 dwg.ActiveLayer = ljx
pt = aDouble([i for j in orginal_middl_pts for i in j * ctfs]) ljx_drawn = acad.model.AddPolyLine(pt) ljx_drawn.LineWeight = 100
"道路中心线"
zxj = acad.doc.layers.add("道路中心线") zxj.color = 2 zxj.LineWeight = 25 try: acad.ActiveDocument.Linetypes.Load("ACAD_ISO10W100", "acadiso.lin") except: pass zxj.Linetype = "ACAD_ISO10W100" dwg.ActiveLayer = zxj
zxj_drewn = acad.model.addline(ctfs * (pt0 - (0, 2, 0)), ctfs * (pt0 + (0, 2, 0))) zxj_drewn.LineWeight = 25
for i in range(6): _ = ljx_drawn.copy() _.Move(APoint(0, 0), APoint(distance_sections * (i + 1), 0) * ctfs) del _ _ = zxj_drewn.copy() _.Move(APoint(0, 0), APoint(distance_sections * (i + 1), 0) * ctfs)
"添加桩号标注"
zh = acad.doc.layers.add("桩号标注") dwg.ActiveLayer = zh
for i in range(7): text_string = "K58+%d" % (70 + 10 * i) insertpt = APoint((distance_sections * i), design_height - 7) * ctfs height = 2.5 * ctfs textobj = acad.model.addtext(text_string, insertpt, height) textobj.Alignment = 7 textobj.textalignmentpoint = insertpt
|