我写了一个判断两个text是否重迭的程序,觉得有点啰嗦,不知诸位有什么更加方便的方法?
;调用方式 ;(if_text_attach (entget (car (entsel))) (entget (car (entsel))))
(defun if_text_attach (text1 text2 / text1_rec text2_rec text1_cor text2_cor text1_cor_x text1_cor_y text2_cor_x text2_cor_y dis1_x dis1_y dis2_x dis2_y list1_x list1_y 1l_b_x 1l_b_y 1r_t_x 1r_t_y 1l_t_x 1l_t_y 1r_b_x 1r_b_y 2l_b_x 2l_b_y 2r_t_x 2r_t_y 2l_t_x 2l_t_y 2r_b_x 2r_b_y num)
(setq text1_rec (textbox text1)) ;得到字的框 (setq text2_rec (textbox text2)) (get_2_number (car text1_rec));取出框的坐标信息 (setq 1l_b_x list1_x 1l_b_y list1_y ) (get_2_number (cadr text1_rec)) (setq 1r_t_x list1_x 1r_t_y list1_y ) (get_2_number (car text2_rec)) (setq 2l_b_x list1_x 2l_b_y list1_y ) (get_2_number (cadr text2_rec)) (setq 2r_t_x list1_x 2r_t_y list1_y ) (setq dis1_x (- 1r_t_x 1l_b_x)) ;得出矩形框的边长 (setq dis1_y (- 1r_t_y 1l_b_y)) (setq dis2_x (- 2r_t_x 2l_b_x)) (setq dis2_y (- 2r_t_y 2l_b_y))
(setq text1_cor (cdr (assoc 10 text1))) ;取出文的控制点(默认在左下角) (setq text1_cor_x (car text1_cor) text1_cor_y (cadr text1_cor) ) (setq text2_cor (cdr (assoc 10 text2))) (setq text2_cor_x (car text2_cor) text2_cor_y (cadr text2_cor) )
;算出两个文本各自四个角点的坐标值 (setq 1l_b_x text1_cor_x) (setq 1l_b_y text1_cor_y) (setq 1r_t_x (+ text1_cor_x dis1_x)) (setq 1r_t_y (+ text1_cor_y dis1_y)) (setq 1l_t_x text1_cor_x) (setq 1l_t_y (+ text1_cor_y dis1_y)) (setq 1r_b_x (+ text1_cor_x dis1_x)) (setq 1r_b_y text1_cor_y)
(setq 2l_b_x text2_cor_x) (setq 2l_b_y text2_cor_y) (setq 2r_t_x (+ text2_cor_x dis2_x)) (setq 2r_t_y (+ text2_cor_y dis2_y)) (setq 2l_t_x text2_cor_x) (setq 2l_t_y (+ text2_cor_y dis2_y)) (setq 2r_b_x (+ text2_cor_x dis2_x)) (setq 2r_b_y text2_cor_y) ;判断四个角点是不是在另一个text之内 (cond ((and (and (< 1l_b_x 2r_t_x) (> 1l_b_x 2l_b_x)) (and (< 1l_b_y 2r_t_y) (> 1l_b_y 2l_b_y))) (setq num 1)) ((and (and (< 1r_t_x 2r_t_x) (> 1r_t_x 2l_b_x)) (and (< 1r_t_y 2r_t_y) (> 1r_t_y 2l_b_y))) (setq num 1)) ((and (and (< 1l_t_x 2r_t_x) (> 1l_t_x 2l_b_x)) (and (< 1l_t_y 2r_t_y) (> 1l_t_y 2l_b_y))) (setq num 1)) ((and (and (< 1r_b_x 2r_t_x) (> 1r_b_x 2l_b_x)) (and (< 1r_b_y 2r_t_y) (> 1r_b_y 2l_b_y))) (setq num 1))
((and (and (< 2l_b_x 1r_t_x) (> 2l_b_x 1l_b_x)) (and (< 2l_b_y 1r_t_y) (> 2l_b_y 1l_b_y))) (setq num 1)) ((and (and (< 2r_t_x 1r_t_x) (> 2r_t_x 1l_b_x)) (and (< 2r_t_y 1r_t_y) (> 2r_t_y 1l_b_y))) (setq num 1)) ((and (and (< 2l_t_x 1r_t_x) (> 2l_t_x 1l_b_x)) (and (< 2l_t_y 1r_t_y) (> 2l_t_y 1l_b_y))) (setq num 1)) ((and (and (< 2r_b_x 1r_t_x) (> 2r_b_x 1l_b_x)) (and (< 2r_b_y 1r_t_y) (> 2r_b_y 1l_b_y))) (setq num 1)) )
(if (= num 1) (princ " This tow text is attached.") (princ " This tow text is separated.") )
)
(defun get_2_number (a / ) (setq list1_x (car a)) (setq list1_y (cadr a)) ) |