找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2634|回复: 4

[每日一码] 用LISP跟踪命令的使用

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2016-5-17 09:23:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×

问题:
I'm programming in LISP and now would like to track how many commands are being used within an AutoCAD session. How could I do it?

解决:
You can find samples about reactors in the LISP Help file, but here is the exact code you would need.

In this case we'll only track commands that actually ended, not including commands that got started and then cancelled - i.e. editor reactor’s commandEnded

When the document is closed we pop up a dialog showing how many commands were used in it since it got opened.

You would need to set up acaddoc.lsp so that it runs the following code for each opened document:

(defun editor-beginClose (reactor-object parameter-list /)
; instead of an alert box write the data somewhere
(alert (strcat "Command count is " (itoa g-command-count)))
)

(defun editor-commandEnded (reactor-object parameter-list /)
(setq g-command-count (1+ g-command-count))
)

(defun StartWatching (/)
; we need the ActiveX system for this
(vl-load-com)
; set the counter
(setq g-command-count 0)
; start the event watcher
(vlr-editor-reactor nil '((:vlr-beginClose . editor-beginClose)(:vlr-commandEnded . editor-commandEnded)))
; don't print anything to the screen
(princ)
)

; this should be started for each opened drawing
(StartWatching)

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 604个

财富等级: 财运亨通

发表于 2016-5-17 10:42:06 | 显示全部楼层
g-command-count这个数计来有什么用处?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 40个

财富等级: 招财进宝

 楼主| 发表于 2016-9-22 23:47:51 | 显示全部楼层

全局变量,用来记录文档关闭前运行过的命令的个数。贴中例子,关闭文档的时候,弹出对话框告知。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 8865个

财富等级: 富甲天下

发表于 2016-9-23 07:21:02 | 显示全部楼层
谢谢 N版分享学习了!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1094个

财富等级: 财源广进

发表于 2021-10-6 04:32:54 | 显示全部楼层
感谢分享用LISP跟踪命令的使用
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-27 06:42 , Processed in 0.164648 second(s), 37 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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