乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 15|回复: 14

[编程交流] Tough Questions - OSNAP Lisp

[复制链接]

12

主题

29

帖子

17

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 12:07:20 | 显示全部楼层 |阅读模式
Tough Questions - OSNAP Lisp
 
 
AutoCAD 2007
I have a quite a few tough questions/requests and I am currently looking for some lisps to solve them.  I have been doing some searching online to find the lisps I need, and although I have been able to find some stuff, I still have some things that I can't seem to find exactly what I am looking for.  I would like to take the opportunity ahead of time to thank every who views my questions and for any help that is given.
 
 
When using lisps I am finding that many of them reset my OSNAP settings, I was wondering if there was a way or a lisp that can be used to keep my OSNAP setting.  So far the only thing I have found is the variable "OSMODE" which has a numerical setting based on the snaps set.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:12:48 | 显示全部楼层
The fact that they reset your osnaps is merely that the LISP is badly written, not the downside of LISP itself.
回复

使用道具 举报

10

主题

8258

帖子

8335

银币

初来乍到

Rank: 1

铜币
31
发表于 2022-7-6 12:16:54 | 显示全部楼层
 
Thanks Lee.  I was going to post something very similar.  Good programmers will reset any variables or settings that are changed for the sake of the functionality of the LISP routine.
回复

使用道具 举报

14

主题

271

帖子

257

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 12:22:25 | 显示全部楼层
I agree with Lee, however if it's a bug in autocad, not lisp, we noticed something similar with the auto savetime settings, so I've modified this lisp we found to work for osnap settings, see what you think. Set the value of the red highlight to the osnap setting you usually use:
 
(not tested & not recommended)
 
  1. (defun C:ALERTME ()(vl-load-com)(setq VTFRXN (vlr-editor-reactor nil '((:VLR-sysVarChanged . VTF)))))(defun VTF (CALL CALLBACK / str val)(setq val [color=Red]39[/color])(if (and(= (strcase (car CALLBACK)) (setq str "OSMODE"))(eq (getvar str) 0))(progn(princ (strcat "Warning: Someone or something has changed your " str " settings.\n" str " has been changed back to " (itoa val)))(setvar str val))))(c:alertme)
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:26:58 | 显示全部楼层
Nice one Steve,
 
I would include a function like this to remove reactor also though!
 
  1. (defun c:rem_reac ( ) (and VTFRXN (vlr-remove VTFRXN)) (setq VTFRXN nil) (princ))
回复

使用道具 举报

14

主题

271

帖子

257

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 12:30:59 | 显示全部楼层
True, good thing to add. I didn't write it, someone at work found it (hopefully they didn't remove a copyright)
 
John, it's not recommended because it could conflict if you have lisps that modify the OSMODE settings.
回复

使用道具 举报

14

主题

271

帖子

257

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 12:37:02 | 显示全部楼层
But we are all just talking to ourselves aren't we...
 
John, it is common courtesy to reply to threads that you start.
Tough Questions - Part 1
Tough Questions - Part 2
Tough Questions - Part 3
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:38:32 | 显示全部楼层
 
1 year ago!... and still no reply...
 
A "user" me thinks.
回复

使用道具 举报

88

主题

346

帖子

281

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
423
发表于 2022-7-6 12:43:17 | 显示全部楼层
Many routines start off by SAVING your current OSMODE setting prior to changing it then resetting it back after the routine completes.
Just make sure your error trapping does the same if the routine is cancelled.
 
If you're trying to learn (like me!) Post the problem routine and the code masters
will not only show you how to fix it, you'll learn what to look for in bad coding as well!!
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-6 12:47:16 | 显示全部楼层
I've found the reactors for resetting the osmode to be quite annoying and it's not that difficult to code your *error* sub to reset everything accordingly.
 
For example:
  1. (defun c:TEst (/ *error* #Osmode #Pnt1 #Pnt2);;; error handler (defun *error* (#Message)   (and #Osmode (setvar 'osmode #Osmode))   (and #Message        (not (wcmatch (strcase #Message) "*BREAK*,*CANCEL*,*QUIT*"))        (princ (strcat "\nError: " #Message))   ) ;_ and ) ;_ defun (setq #Osmode (getvar 'osmode)) (setvar 'osmode 4105) (and (setq #Pnt1 (getpoint "\nSpecify first point: "))      (setq #Pnt2 (getpoint #Pnt1 "\nSpecity next point: "))      (command "_.line" "_non" #Pnt1 "_non" #Pnt2 "") ) ;_ and (and #Osmode (setvar 'osmode #Osmode)) ;; or you can type: (*error* nil) (princ)) ;_ defun
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 10:22 , Processed in 0.622711 second(s), 83 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表