乐筑天下

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

[编程交流] How do I protect the user'

[复制链接]

7

主题

18

帖子

11

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-6 07:10:07 | 显示全部楼层 |阅读模式
My program uses a simple error catch as the only exit point. The problem is the user can undo the setvar calls that reset the system variables and leave the variables in a undesirable state. "Undo" "C" "NONE" will make all previous actions undoable. How do we make it impossible to undo the setvar's while not blowing away the entire undo history?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:41:33 | 显示全部楼层
I use this structure:
  1. (defun c:mycommand ( / *error* )   (defun *error* ( m )       [color=green]< Reset System Variables >[/color]       (LM:endundo (LM:acdoc))       < ... >   )   (LM:startundo (LM:acdoc))   [color=green]< Set System Variables >[/color]   < ... >   [color=green]< Reset System Variables >[/color]   (LM:endundo (LM:acdoc)))
With the following library functions:
  1. [color=GREEN];; Start Undo  -  Lee Mac[/color][color=GREEN];; Opens an Undo Group.[/color]([color=BLUE]defun[/color] LM:startundo ( doc )   (LM:endundo doc)   ([color=BLUE]vla-startundomark[/color] doc))[color=GREEN];; End Undo  -  Lee Mac[/color][color=GREEN];; Closes an Undo Group.[/color]([color=BLUE]defun[/color] LM:endundo ( doc )   ([color=BLUE]while[/color] ([color=BLUE]=[/color] 8 ([color=BLUE]logand[/color] 8 ([color=BLUE]getvar[/color] 'undoctl)))       ([color=BLUE]vla-endundomark[/color] doc)   ))[color=GREEN];; Active Document  -  Lee Mac[/color][color=GREEN];; Returns the VLA Active Document Object[/color]([color=BLUE]defun[/color] LM:acdoc [color=BLUE]nil[/color]   ([color=BLUE]eval[/color] ([color=BLUE]list[/color] '[color=BLUE]defun[/color] 'LM:acdoc '[color=BLUE]nil[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))))   (LM:acdoc))
When considering the order of operations & Undo Group markers within the program & error handler, be aware that when an Undo call is issued, AutoCAD will undo all operations following the end of an Undo Group before Undo'ing the Group.
回复

使用道具 举报

7

主题

18

帖子

11

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-6 08:06:30 | 显示全部楼层
Thanks Lee Mac. I didn't mention I needed it to step back through a loop, but your post gave me the pattern to make it work. Now, I just need to learn the fancy VLA stuff so I quiet it down....(command "_.undo...) is noisy!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 08:28:16 | 显示全部楼层
You're welcome!
 
 
Temporarily disable CMDECHO
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-3 17:54 , Processed in 0.921261 second(s), 60 queries .

© 2020-2025 乐筑天下

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