本帖最后由 vlisp2012 于 2013-10-9 16:27 编辑
通过ssget获得的选择集的排序,无法很好的控制,每次下面材的时候,都是通过fence,画线选择板块,很繁琐。
我想编辑一个程序,通过x坐标和y坐标来对面材(封闭多段线)排序后,进行板块的编号,得到排序后的选择集如下:
(((434613.0 -21571.4) ) ((441013.0 -21571.4) ) ((433388.0 -21571.4) ) ((441013.0 -19151.4) ) ((439413.0 -19151.4) ) ((436213.0 -19151.4) ) ((434613.0 -19151.4) ) ((433388.0 -19151.4) ) ((437813.0 -19151.4) ) ((441013.0 -16711.4) ) ((439413.0 -16711.4) ) ((437813.0 -16711.4) ) ((436213.0 -16711.4) ) ((434613.0 -16711.4) ) ((433388.0 -16711.4) ) ((433388.0 -14031.4) ) ((434613.0 -14031.4) ) ((436213.0 -14031.4) ) ((437813.0 -14031.4) ) ((439413.0 -14031.4) ) ((441013.0 -14031.4) ))
我想问大家的是,怎样将上表中,为排序而采用的坐标删掉呢?
我想要的表如下:
(() () () ( ) ( ) ( )…… )
程序如下:(defun c:tt ()
(command "undo" "be")
(princ "\n 选择四边形:")
(setq no (getint "\n起始编号<0>:"))
(if (null no) (setq no 0))
(setq no_ban (getstring "\n板块编号<1B>:"))
(if (= no_ban "") (setq no_ban "1B"))
(princ "\n请选择要排序的实体...")
(if (setq ss (ssget '((0 . "LWPOLYLINE"))))
(progn
;; 1、获取点位表
(setq lst '()
i 0
lst0 '()
)
(repeat (sslength ss)
(setq en (ssname ss i))
;;; ent (entget en)
;;; pt (cdr (assoc 10 ent))
(setq obj (vlax-ename->vla-object en))
;; 得到包围框
(setq avc (vla-GetBoundingBox Obj 'minpt 'maxpt))
(setq minPt (vlax-safearray->list minPt)
maxPt (vlax-safearray->list maxPt)
PtCen (list (/ (+ (car minpt) (car maxpt)) 2)
(/ (+ (cadr minpt) (cadr maxpt)) 2)))
(setq lst0 (list PtCen en))
(setq lst (cons lst0 lst)
i (1+ i)
)
)
;; 2、排序
(setq
lst (vl-sort
lst
(function
(lambda (e1 e2)
(if (equal (cadr e1) (cadr e2) 50)
(< (caar e1) (caar e2))
(< (cadar e1) (cadar e2))
)
)
)
)
)
)
(bh lst no no_ban)
)
(princ)
)
请各位大侠帮忙!!!