本帖最后由 andyzha 于 2023-5-15 08:50 编辑
偶得一个快速对齐的程序,有个小bug,使用过程中,有时候不能释放捕捉参数,症状就是把所有捕捉点都清除了,求完善,不胜感激。
多谢hhh454点拨,已经修改完善。
- (defun c:TT( / )
- (vl-load-com)
- ;错误恢复捕捉
- (defun *MYERR* (MSG)
- (setvar "CMDECHO" CMD_OLD)
- (setvar "OSMODE" OS_OLD)
- (setq *ERROR* *OLDERR*)
- (if (= MSG "完美退出。谢谢使用。")
- (princ (strcat "\\n>>>" MSG))
- (princ "\\n>>>虽然中途退出了,对象捕捉已经被恢复。")
- )
- (princ)
- )
- (setq *OLDERR* *ERROR*
- *ERROR* *MYERR*
- OS_OLD (getvar "OSMODE")
- CMD_OLD (getvar "CMDECHO")
- )
- ;----开始系统变量备份----
- (setvar "cmdecho" 0);_关闭命令提示
- (command "._undo" "_begin")
- (setq osmode_bak (getvar "osmode"));_记录捕捉
- (setvar "osmode" 0);_关闭捕捉,代码需要用捕捉就删除这行,也可以按照下面的增加捕捉的代码,2选一
- (setq clayer_bak (getvar "clayer"));_记录当前图层
- (setq ss (ssget))
- (setq e1 (entsel "\n选择要对齐的边线"))
- (while (= e1 nil) (setq e1 (entsel "\n选择要对齐的边线")))
- (setq pt1 (osnap (cadr e1) "mid"))
- (setq pt2 (osnap (cadr e1) "nea"))
- (setq e2 (entsel "\n对齐参照线"))
- (while (= e2 nil) (setq e2 (entsel "\n对齐参照线")))
- (setq pt3 (osnap (cadr e2) "mid"))
- (setq pt4 (osnap (cadr e2) "nea"))
- (command "_.align" ss "" pt1 pt3 pt2 pt4 "" "n")
- (setvar "osmode" osmode_bak);_还原捕捉
- (setvar "clayer" clayer_bak);_还原图层
- (command "._undo" "_end")
- (setvar "cmdecho" 1);_打开命令提示
- (princ);_关闭程序返回值
- );_程序结束
|