- ;点排序画线
- (defun c:test()
- (setq cmd (getvar "cmdecho"))
- (setvar "cmdecho" 0)
- (command "_undo" "be")
- (if (setq ssa (ssget '((0 . "point"))))
- (progn
- (setq pts (mapcar '(lambda(ent)(cdr (assoc 10 (entget ent))))
- (vl-remove-if 'listp (mapcar 'cadr (ssnamex ssa)))
- )
- )
- ;按圆弧方式排序
- (setq p0 (mapcar '/ (apply 'mapcar (cons '+ pts))
- (list (length pts) (length pts))
- )
- )
- (setq pts (vl-sort pts '(lambda(a b) (< (angle p0 a) (angle p0 b)))))
-
- ;或者按从左至右、由上往下方式排序
- ;(setq pts (vl-sort pts '(lambda(a b)(if (equal (car a) (car b))
- ; (> (cadr a) (cadr b))
- ; (< (car a) (car b))
- ; )
- ; )
- ; )
- ; )
-
- ;画多段线
- (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
- (cons 90 (length pts))
- )
- (mapcar '(lambda(x)(list 10 (car x) (cadr x))) pts)
- )
- )
- )
- )
- (command "_undo" e)
- (setvar "cmdecho" cmd)
- (princ)
- )
|