此反应器回调函数实现目的是:如果一个附着该反应器的文字移动或者修改内容后压到别的文字,则移开那个被压到的文字。
思路:通过ssget选择以文字四角所围成的区域的文字,若返回选择集为空nil则没有碰撞,否则计算被压倒的文字新坐标并移开文字到新坐标。
反应器使用ssget这样的交互函数是禁止的,但是我想不到更好的搜索算法来检查是否碰撞,所以里面的ssget函数参数都是预定义好的而不是用户交互输入的。
希望高手指点下改进方法,有个问题请教就是在反应器(第一次)触发后 while循环没法完全执行就退出了并又触发(第二次)反应器的执行,所以文字移动不到想要的位置,求教大神是什么原因......- (defun RCBF:obj-delete-text(owner_obj reactor_obj arg_list / m_ename pt_10 ang_50 ucs_dir pt1 pt2 pt3 pt4 b h pt_list ss tmp)
- (princ "\n.\n反应器开始执行...")
- (setq m_ename (vlax-vla-object->ename owner_obj))
- ;;碰撞检查start
- (setq pt_10 (getitern m_ename 10) ang_50 (getitern m_ename 50) ucs_dir (append pt_10 (list ang_50)))
- (setq pt1 (textbox (entget m_ename)) pt3 (cadr pt1) pt1 (car pt1) b (car pt3) h (cadr pt3))
- (setq pt2 (polar pt1 0.0 b) pt4 (polar pt1 (/ pi 2.0) h) pt_list (list pt1 pt2 pt3 pt4))
- (setq pt_list (mapcar (function(lambda(x)(trans (trans-ucs-obj->w x ucs_dir) 0 1))) pt_list))
- (if (setq ss (ssget "_CP" pt_list '((0 . "TEXT"))))
- (if (setq tmp (ssdel m_ename ss)) (setq ss tmp))
- )
- ;;碰撞检查end
-
- (if ss (princ (strcat "\n文字碰撞:" (getitern (ssname ss 0) 1)))(princ "\n没有碰撞到文字..."))
- (if ss (progn
- (setq m_text (ssname ss 0)
- m_text_10 (getitern m_text 10)
- m_text_50 (getitern m_text 50)
- m_text_40 (getitern m_text 40)
- pt_text_1 (textbox (entget m_text))
- pt_text_3 (cadr pt_text_1) pt_text_1 (car pt_text_1)
- pt_text_2 (polar pt_text_1 0.0 (car pt_text_3))
- pt_text_4 (polar pt_text_1 (/ pi 2.0) (cadr pt_text_3))
- pt_text_list (list pt_text_1 pt_text_2 pt_text_3 pt_text_4)
- pt_end1 m_text_10 pt_end2 m_text_10 right_times 0 left_times 0)
- (while ;;计算在碰撞后向右移动多少次可以不再碰撞
- (setq pt_start pt_end1 pt_end1 (polar pt_start m_text_50 m_text_40)
- right_times (1+ right_times)
- ucs_text_dir (append pt_end1 (list m_text_50))
- pt_text_list (mapcar (function(lambda(x)(trans (trans-ucs-obj->w x ucs_text_dir) 0 1))) pt_text_list)
- ss_1 (ssget "_CP" pt_text_list '((0 . "TEXT")))
- )
- (princ "\nR移动次数:")(princ right_times)
- (princ "\nss_1=")(princ ss_1)
- (princ "\n图原名=")(princ (getitern (ssname ss_1 0) -1))
- )
- (while
- ;;计算在碰撞后向左移动多少次可以不再碰撞
- (setq pt_start pt_end2 pt_end2 (polar pt_start (+ m_text_50 pi) m_text_40)
- left_times (1+ left_times)
- ucs_text_dir (append pt_end2 (list m_text_50))
- pt_text_list (mapcar (function(lambda(x)(trans (trans-ucs-obj->w x ucs_text_dir) 0 1))) pt_text_list)
- ss_2 (ssget "_CP" pt_text_list '((0 . "TEXT")))
- )
- (princ "\nL移动次数:")(princ left_times)
- (princ "\nss_2=")(princ ss_2)
- (princ "\n图原名=")(princ (getitern (ssname ss_2 0) -1))
- )
- (if (<= right_times left_times)(upobj m_text 10 pt_end1)(upobj m_text 10 pt_end2)) ;;根据向左或是向右移动次数判断向左还是右移动
- (princ)
- ))
- ;(upobj m_text 10 pt_end)
- (princ "\n反应器执行结束...\n.")
- )
|