- (defun c:tt()
- (setq ss (ssget '((0 . "lwpolyline"))));选择多段线
- (setq i 1 lst nil);初始化变量,设置i为1的原因是方便j取值
- (repeat (- (sslength ss) 1);外循环开始,循环次数为多段线个数减1
- (setq en (entget (ssname ss (- i 1))));得到DXF
- (setq lst (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) en)));提取点表
- (setq lst_ys_x (mapcar 'car (vl-sort lst '(lambda (e1 e2) (< (car e1) (car e2))))));按照X坐标从小到大排序并提取X坐标组成表
- (setq lst_ys_y (mapcar 'cadr (vl-sort lst '(lambda (e1 e2) (< (cadr e1) (cadr e2))))));按照Y坐标从小到大排序并提取Y坐标组成表
- (setq j 0);初始化j为0
- (setq j (+ j i));j的值为i+j
- (repeat (- (sslength ss) i);内循坏开始,循坏次数为多段线个数减去i
- (setq en_1 (entget (ssname ss j)));得到DXF
- (setq lst_1 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) en_1)));提取点表
- (setq lst_ys_x_1 (mapcar 'car (vl-sort lst_1 '(lambda (e1 e2) (< (car e1) (car e2))))));同样按照X坐标从小到大排序并提取X坐标组成表
- (setq lst_ys_y_1 (mapcar 'cadr (vl-sort lst_1 '(lambda (e1 e2) (< (cadr e1) (cadr e2))))));同样按照Y坐标从小到大排序并提取Y坐标组成表
- (if (and (equal lst_ys_x lst_ys_x_1 1e-5) (equal lst_ys_y lst_ys_y_1 1e-5));对比两个X和两个Y的表看是否一致,一致就删除
- (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object (ssname ss j))));因为已经删除的线会重复删除,所以加错误处理
- )
- (setq j (1+ j))
- );内循环结束
- (setq i (1+ i))
- );外循坏结束
- (princ)
- )
|