def test_scan_entities_1(): cad = AutoCAD() s = set() for en in cad.selecting(): if en.entity_type == 'Hatch': s.add(en.layer) print(s)
def test_intepolate_polyline_dx(): '''多段线加密 and 分割为多段线的碎片''' cad = AutoCAD() for pl in cad.selecting(): # distance = 0.3 distance = 0.2 interpl, report = cad.interpolate_polyline(pl, distance=distance, delete_original=True, break_at_vertexes=True) puts('多段线加密 分割为多段线的碎片')
def todo_read_gcd(): '''读取高程点''' cad = AutoCAD() file_path = 'path' for line in datalines(open(file_path).read()): index, _, x, y, elevation = line.split(',') cad.add_text(elevation, origin=(float(x), float(y))) cad.add_point(float(x), float(y))
def test_intepolate_polyline(): '''多段线加密''' cad = AutoCAD() for pl in cad.selecting(): # distance = 0.3 distance = 0.2 interpl, report = cad.interpolate_polyline(pl, distance=distance, delete_original=True, break_at_vertexes=False) interpl.color = 'green' puts('多段线加密')
def test_redraw_vertex_sequence(): '''重绘多段线的顶点顺序''' cad = AutoCAD() for pl in cad.selecting(): first = None # first = -1 redrawpl = cad.redraw_vertex_sequence(pl, first=first, hint=False, auto_reverse=True) redrawpl.color = 'yellow' puts('重绘顶点顺序')
def test_de_intepolate_polyline(): '''多段线抽稀''' cad = AutoCAD() for pl in cad.selecting(): interpl, report = cad.de_interpolate_polyline(pl, threshold=3) if abs(interpl.area - pl.area) < 30: interpl.color = 'green' pl.delete() else: interpl.delete() puts('多段线抽稀 report=')
def todo_find_nearest_text(): cad = AutoCAD() entities = list(cad.selecting()) numbers = [] names = [] for text in entities: if text.color == 'black': names.append(text) else: numbers.append(text) from Converter import SpaceCoordinate dist = SpaceCoordinate().distance2 for number in numbers: near = min(names, key=lambda name: dist(name.mid_point, number.mid_point)) | puts() near.color = 'cyan'
def todo_detect_duplicate(): cad = AutoCAD() heding = [] dk = [] for en in cad.selecting(): if en.layer == '0': dk.append(en) else: heding.append(en) areas = set(round(en.area, 0) for en in heding) mid_points = set('{:.0f}-{:.0f}'.format(*en.mid_point) for en in heding) print(areas) print(mid_points) for en in dk: if round(en.area, 0) in areas: if '{:.0f}-{:.0f}'.format(*en.mid_point) in mid_points: print(en) # en.layer = '重复' en.color = 'yellow'
def test_rebuild_arc_polyline(): '''将加密后的poly转为圆弧poly 处理选中的多段线 如果有选中的点, 将这些点作为分隔符''' cad = AutoCAD() polylines = [] points = [] for en in cad.selecting(): if en.entity_type == 'Point': points.append(en) elif en.entity_type == 'Polyline' and en.closed: polylines.append(en) dist = 3 for pl in polylines: arcpl = cad.rebuild_arc_polyline(pl, threshold=dist, segment_points=[(p.x, p.y) for p in points]) arcpl.color = 'yellow' report = '转为圆弧poly 原面积={:.4f} 新面积={:.4f} 相差={:.4f} ({:.4%})' puts(report.format(pl.area, arcpl.area, arcpl.area - pl.area, (arcpl.area-pl.area)/pl.area))
def test_gcd_string(): '''读取高程点 读取坐标点''' s = ''' # 01,,376173,875806,20.812 # 01,,376167,875809,20.881 # 01,,376298,875822,20.780 # 01,,376295,875827,20.744 # 01,,376399,875735,20.760 # 01,,376405,875734,20.872 j6,,376230.527,875750.679,20.947 j5,,376226.292,875743.894,20.787 j8,,376314.162,875580.859,20.039 j7,,376308.053,875584.223,20.903 j1,,376051.421,875669.464,20.911 j2,,376122.484,875534.670,20.916 j3,,376121.527,875531.260,20.973 ''' s = ''' 376897.510 871120.891 376917.510 871120.891 376917.510 871100.891 376897.510 871100.891 376127.488 878184.564 376172.488 878184.564 376172.488 878174.564 376127.488 878174.564 ''' cad = AutoCAD() for line in datalines(s): index, _, x, y, elevation = line.split(',') cad.add_text(elevation, origin=(float(x), float(y))) cad.add_point(float(x), float(y))
def test_compare_area(): cad = AutoCAD() r = cad.compare_area(*list(cad.selecting())) print(r)
def test_remove_same_point_polyline(): '移除poly中的重复节点' cad = AutoCAD() for pl in cad.selecting(): plnew, report = cad.remove_same_points_polyline(pl, threshold=0.0001) puts(report)
from pylon import datalines from pylon import puts from autocad import AutoCAD # from lib.entity import AutoCADEntityError cad = AutoCAD() selecting_entities = list(cad.selecting()) def test_dim_area(): '标注对象面积' cad.dim_area(selecting_entities) '标注对象面积 加单位后缀 保留5位小数' cad.dim_area(selecting_entities, unit='m²', precision=5) print(list(selecting_entities)) def test_dim_road(): '''标注道路名称''' cad.prompt('----------------\n--------------') cad.prompt('标注道路名称 鼠标指定起点终点') r = cad.dim_road(name='测试道路', rotate=True, match_existing=False, arc_path=False) print(r) cad.prompt('----------------\n--------------') cad.prompt('标注道路名称 如果之前已选中文字则匹配选中文字样式') r = cad.dim_road(name='测试道路', rotate=True, match_existing=True, arc_path=False) print(r)