请教点表按照从左往右,从上到下排序怎么弄?
本帖最后由 sbwdx 于 2023-5-1 14:47 编辑以下代码来自论坛前辈:
(defun c:tt ( / box e i ss)
(defun ebox (e / pa pb)
(Vlax-Invoke-Method (Vlax-Ename->Vla-Object e ) 'GetBoundingBox 'pa 'pb )
(setq pa (trans (vlax-safearray->list pa) 0 1)
pb (trans (vlax-safearray->list pb) 0 1)
)
(list pa pb)
)
(setq ss (ssget '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
box (ebox e)
)
(vl-cmdf "rectang" (car box) (cadr box))
)
)
想请教一下大家, e对象的box 一组坐标点pa pb 是随机排序的,怎么对e对象的一组坐标点pa pb,按照从左往右,从上到下排序后
vl-cmdfrectang 按照排序后,从左往右,从上到下排序依次绘制矩形,谢谢!
(defun c:tt (/ box e i ss)
(defun ebox (e / pa pb)
(Vlax-Invoke-Method
(Vlax-Ename->Vla-Object e)
'GetBoundingBox
'pa
'pb
)
(setq pa (trans (vlax-safearray->list pa) 0 1)
pb (trans (vlax-safearray->list pb) 0 1)
)
(list pa pb)
)
(setq thisdrawing (vla-get-activedocument
(vlax-get-acad-object)))
(vla-startundomark thisdrawing)
(setq ss (ssget '((0 . "INSERT")))
boxlst nil
FUZZ 0;;;;坐标误差,相差这么大被认为是一行
)
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
box (ebox e)
boxlst (cons box boxlst)
)
)
(setq
boxlst (vl-sort
boxlst
(function (lambda (e1 e2)
(if (equal (cadr (car e1)) (cadr (car e2))FUZZ)
(< (car (car e1)) (car (car e2)))
(> (cadr (car e1)) (cadr (car e2)))
)
)
)
)
)
;;;(setq i 1)
(foreach box boxlst
(vl-cmdf "rectang" (car box) (cadr box))
;;; (Make-TEXT (car box) (rtos i 2 0) 0.11)
;;; (SETQ I(1+ I))
)
(vla-endundomark thisdrawing)
)
(defun Make-TEXT (pt str Textheigh)
(entmakeX
(list '(0 . "TEXT") (cons 1 str) (cons 10 pt) (cons 40 Textheigh))
)
)
左右优先,上下其次,fuzz用于上下坐标误差内还认为是同一行
页:
[1]