明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1771|回复: 5

[函数] 求助 程序在正交动作后不能自动返回极轴

[复制链接]
发表于 2011-6-29 23:55 | 显示全部楼层 |阅读模式

正交拉伸后自返回极轴捕捉
(defun c:s()
(setq orth(getvar"orthomode"))
(setvar"orthomode"1)(setvar"autosnap"55)(setvar"osmode"16383)
(command"stretch" "C")
(while(=(logand(getvar"CmdActive")1)1)(command pause))
(setvar"autosnap"63))
不能先选择后执行,中途退出时不能返回极轴

正交移动后自返回极轴捕捉
(defun c:mn()
(setvar"orthomode"1)(setvar"autosnap"55)(setvar"osmode"16383)
(command "move"(ssget)""")(getpoint "\n基点:)
(while(=(logand(getvar"CmdActive")1)1)(command pause))
(setvar"autosnap"63))
不能返回极轴
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2011-6-30 00:29 | 显示全部楼层
中途退出时不能返回极轴的原因是没有作出错处理,需要定义出错处理函数,以便程序出错或用户退出时进行处理,可参考我最近贴的些程序。
第二的程序的(command "move"(ssget)""")(getpoint "\n基点:)
应该为(command "move"(ssget)"")(getpoint "\n基点:")
 楼主| 发表于 2011-6-30 13:08 | 显示全部楼层
回复 zhynt 的帖子

谢谢大师的帮助,我试试看。
 楼主| 发表于 2011-7-1 23:02 | 显示全部楼层
回复 zhynt 的帖子

在坛里搜了一打“出错处理”.........“洞口”,看不懂啊
还望zhynt大师指点

正交拉伸后自返回极轴捕捉
(defun c:s()
(setvar"orthomode"1)
(command"stretch"(ssget)"")
(while(=(logand(getvar"CmdActive")1)1)(command pause))
(setvar"autosnap"63)(setvar"osmode"16383)(princ))

正交移动后自返回极轴捕捉
(defun c:mn()
(setvar"orthomode"1)
(command "move"(ssget)"")
(while(=(logand(getvar"CmdActive")1)1)(command pause))
(setvar"autosnap"63)(setvar"osmode"16383)(princ))


正交镜像后自返回极轴捕捉
(defun c:im()
(setvar"orthomode"1)
(command"mirror"(ssget)"")
(while(=(logand(getvar"CmdActive")1)1)(command pause))
(setvar"autosnap"63)(setvar"osmode"16383)(princ))
发表于 2011-7-1 23:47 | 显示全部楼层
类似这样:

  1. ;;出错处理
  2. (defun err (s)
  3.   (if (and (/= s "console break")
  4.            (/= s "Function cancelled")
  5.            (/= s "quit/exit abort")
  6.       )
  7.     (progn
  8.       (setvar "osmode" oldos)     
  9.       (setvar "autosnap" oldosn)
  10.       (setvar "orthomode" oldor)
  11.       (setq *error* olderr)
  12.       (command "_.undo" "e")
  13.        (setvar "cmdecho" oldcmd)
  14.       (princ (strcat "\n程序出错或用户退出:" s))
  15.     )
  16.   )
  17. )
  18. ;;;备份系统变量
  19. (defun bak ()
  20.   (setq        oldcmd        (getvar "cmdecho"))
  21.   (setvar "cmdecho" 0)
  22.   (command "_.undo" "be")
  23.   (setq        oldos        (getvar "osmode")
  24.         oldosn (getvar "autosnap")
  25.         oldor (getvar "orthomode")       
  26.         olderr        *error*
  27.         *error*        err
  28.   )
  29.   (setvar "orthomode" 1)
  30.   
  31. )
  32. ;;恢复系统变量
  33. (defun rebak ()
  34.   (setvar "osmode" oldos)  
  35.   (setvar "autosnap" oldosn)
  36.   (setvar "orthomode" oldor)
  37.   (setq *error* olderr)
  38.   (command "_.undo" "e")
  39.   (setvar "cmdecho" oldcmd)
  40. )
  41.     ;;正交拉伸后自返回极轴捕捉
  42. (defun c:ss ()
  43.   (bak)  
  44.   (command "stretch" (ssget) "")
  45.   (while (= (logand (getvar "CmdActive") 1) 1)
  46.     (command pause)
  47.   )
  48.   (rebak)
  49.   (princ)
  50. )

评分

参与人数 1金钱 +50 收起 理由
669423907 + 50 谢谢热情帮助!

查看全部评分

 楼主| 发表于 2011-7-2 17:02 | 显示全部楼层
本帖最后由 669423907 于 2011-7-2 17:08 编辑

回复 zhynt 的帖子

还zhynt大师帮忙看看,我在 (rebak) 的后面加了(setvar"autosnap"63)(setvar"osmode"16383),
中途按 ESC 退出可以返回极轴了。
但是发现以下问题:

1,不能先选择后操作了
2,( ss )拉伸时中途按右键退出,图形会变形
3,( mn )移动时中途按右键退出,图形会会跑
4,选择对象后,要按两次 ESC 才能完全退出

麻烦 zhynt大师有空时再帮看看,不胜感激了。

;;出错处理
(defun err (s)
  (if (and (/= s "console break")
           (/= s "Function cancelled")
           (/= s "quit/exit abort")
      )
    (progn
      (setvar "osmode" oldos)     
      (setvar "autosnap" oldosn)
      (setvar "orthomode" oldor)
      (setq *error* olderr)
      (command "_.undo" "e")
       (setvar "cmdecho" oldcmd)
      (princ (strcat "\n程序出错或用户退出:" s))
    )
  )
)
;;;备份系统变量
(defun bak ()
  (setq        oldcmd        (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (command "_.undo" "be")
  (setq        oldos        (getvar "osmode")
        oldosn (getvar "autosnap")
        oldor (getvar "orthomode")        
        olderr        *error*
        *error*        err
  )
  (setvar "orthomode" 1)
  
)
;;恢复系统变量
(defun rebak ()
  (setvar "osmode" oldos)  
  (setvar "autosnap" oldosn)
  (setvar "orthomode" oldor)
  (setq *error* olderr)
  (command "_.undo" "e")
  (setvar "cmdecho" oldcmd)
)
    ;;正交拉伸后自返回极轴捕捉
(defun c:ss()
  (bak)  
  (command "stretch" (ssget) "")
  (while (= (logand (getvar "CmdActive") 1) 1)
    (command pause)
  )
  (rebak)(setvar"autosnap"63)(setvar"osmode"16383)
  (princ)
)



正交移动后自返回极轴捕捉
(defun c:mn()
(bak)
(command"move"(ssget)"")
(while(=(logand(getvar"CmdActive")1)1)(command pause))
(rebak)(setvar"autosnap"63)(setvar"osmode"16383)
(princ))

正交镜像后自返回极轴捕捉
(defun c:im()
(bak)
(command"mirror"(ssget)"")
(while(=(logand(getvar"CmdActive")1)1)(command pause))
(rebak)(setvar"autosnap"63)(setvar"osmode"16383)
(princ))

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-26 12:26 , Processed in 0.347106 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表