试试(向量公式来自高飞鸟版主)
- (defun c:zxhb (/ MAT:v-v MAT:vxv get_dxf at_line
- make_linebylst get_online ss
- a lst n lst1 en
- jg
- )
- (defun MAT:v-v (v1 v2)
- (mapcar '- v1 v2)
- )
- (defun MAT:vxv (u v)
- (list
- (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
- (- (* (car v) (caddr u)) (* (car u) (caddr v)))
- (- (* (car u) (cadr v)) (* (car v) (cadr u)))
- )
- )
- (defun get_dxf (en n /) (cdr (assoc n (entget en))))
- (defun at_line (en1 pt /)
- (equal '(0 0 0)
- (MAT:vxv (MAT:v-v (get_dxf en 10) pt)
- (MAT:v-v (get_dxf en 11) pt)
- )
- 1e-6
- )
- )
- (defun make_linebylst (lst / lst1 a b x1 x2 y1 y2)
- (setq
- lst1
- (vl-sort
- (apply
- 'append
- (mapcar '(lambda (x) (list (get_dxf x 10) (get_dxf x 11)))
- lst
- )
- )
- '(lambda (a b)
- (setq x1 (car a)
- x2 (car b)
- y1 (cadr a)
- y2 (cadr b)
- )
- (if (equal x1 x2 1e-6)
- (> y1 y2)
- (< x1 x2)
- )
- )
- )
- )
- (entmakex (list '(0 . "line")
- (cons 8 (get_dxf (car lst) 8))
- (cons 10 (car lst1))
- (cons 11 (last lst1))
- )
- )
- )
- (defun get_online (en lst / en1 lst1 lst2 out)
- (setq lst1 (list en)
- lst2 nil
- )
- (repeat (length lst)
- (setq en1 (car lst)
- lst (cdr lst)
- )
- (if (and
- (at_line en (get_dxf en1 10))
- (at_line en (get_dxf en1 11))
- )
- (setq lst1 (cons en1 lst1))
- (setq lst2 (cons en1 lst2))
- )
- )
- (setq en1 (make_linebylst lst1))
- (mapcar 'entdel lst1)
- (list en1 lst2)
- )
- (setq ss (ssget '((0 . "line"))))
- (setq a (sslength ss))
- (setq lst nil)
- (repeat (setq n a)
- (setq lst (cons (ssname ss (setq n (1- n))) lst))
- )
- (while lst
- (setq en (car lst)
- lst (cdr lst)
- )
- (setq jg (get_online en lst)
- lst (cadr jg)
- lst1 (cons (car jg) lst1)
- )
- )
- (princ (strcat "\n共"
- (rtos a 2 0)
- "条直线合并为"
- (rtos (length lst1) 2 0)
- "条直线"
- )
- )
- (princ)
- )
|