fcfcadd 发表于 2022-7-6 12:11:31

我写lisp例程已经有十多年了。我不知道该怎么组合。基本上,我在问是否有人可以用lisp或vba为我编写一个简单的。

Lee Mac 发表于 2022-7-6 12:15:59

例子:
 

(defun c:GetTime (/ toDate *error* ofile)

(defun toDate (var format)
   (menucmd (strcat "m=$(edtime,$(getvar," var ")," format ")")))

(defun *error* (msg)
   (and ofile (close file))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))   

(if (or *logfile* (setq *logfile* (getfiled "Create Log File" "" "txt" 1)))
   (progn
   (setq ofile (open *logfile* "a"))

   (write-line (strcat "DATE: " (toDate "DATE" "DD.MO.YY HH.MM.SS"))            ofile)
   (write-line (strcat "DRAWING: " (getvar 'DWGPREFIX) (getvar 'DWGNAME))         ofile)
   (write-line (strcat "CREATED: " (toDate "TDCREATE" "DD.MO.YY HH.MM.SS"))       ofile)
   (write-line (strcat "TOTAL EDITING TIME: " (toDate "TDINDWG" "HH.MM.SS") "\n") ofile)

   (setq ofile (close ofile))))

(princ))

   

fcfcadd 发表于 2022-7-6 12:18:42

我将尝试一下,看看是否可以让它自动运行。非常感谢你。

Lee Mac 发表于 2022-7-6 12:22:46

 
当你说自动,你是什么意思?图形何时保存?如果您希望它自动运行,您可能需要将其用作反应堆中的回调函数,由save命令触发。

fcfcadd 发表于 2022-7-6 12:23:03

我需要它在open命令和close命令上运行。所以每次我打开一个新的图纸,然后当我关闭该图纸。即使我必须在收盘时回答提示,让它运行也没问题。

Lee Mac 发表于 2022-7-6 12:27:13

您可以使用命令反应器,在打开命令结束后以及关闭命令启动时做出反应。
 
这里有一些关于反应堆的帮助,
 
http://www.afralisp.net/vl/reactors1.htm
 
Visual LISP帮助文件中也有一些好东西

fcfcadd 发表于 2022-7-6 12:31:26

是的,我以前去过那个网站,他以前也有一个vba程序,可以记录时间,但现在它有一些错误,我无法让它正常工作。

Lee Mac 发表于 2022-7-6 12:32:36

这应该适合您:
 

(defun TimeReac nil
(vl-load-com)
(if (not (vl-position "TIMEREACT"
            (mapcar (function strcase)
                  (mapcar (function vlr-data)
                            (mapcar (function cadr)
                                    (vlr-reactors :vlr-command-reactor))))))
   (progn
   (vlr-command-reactor "TIMEREACT"
       (list
         (cons :vlr-commandWillStart 'GetTime_C)
         (cons :vlr-commandEnded   'GetTime_O)))

   (princ "\n<< Reactor Initiated >>"))

   (princ "\n<< Reactor Already Running >>"))

(princ))

(TimeReac)


(defun GetTime_O (Reactor Args)
(if (eq "OPEN" (strcase (car Args)))
   (GetTime))
(princ))


(defun GetTime_C (Reactor Args)
(if (eq "CLOSE" (strcase (car Args)))
   (GetTime))
(princ))      


(defun GetTime (/ toDate *error* ofile)

(defun toDate (var format)
   (menucmd (strcat "m=$(edtime,$(getvar," var ")," format ")")))

(defun *error* (msg)
   (and ofile (close file))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))   

(if (setq ofile (open (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME) "_log.txt") "a"))
   (progn   

   (write-line (strcat "DATE: "    (toDate "DATE" "DD.MO.YY HH.MM.SS"))         ofile)
   (write-line (strcat "DRAWING: " (getvar 'DWGPREFIX) (getvar 'DWGNAME))         ofile)
   (write-line (strcat "CREATED: " (toDate "TDCREATE" "DD.MO.YY HH.MM.SS"))       ofile)
   (write-line (strcat "TOTAL EDITING TIME: " (toDate "TDINDWG" "HH.MM.SS") "\n") ofile)

   (setq ofile (close ofile))))

(princ))



(defun c:TimeOFF (/ Reac)
(vl-load-com)
(if (and (setq Reac
            (car
            (vl-remove-if-not
                (function
                  (lambda (x)
                  (eq "TIMEREACT" (strcase (vlr-data x)))))
                (mapcar (function cadr)
                  (vlr-reactors :vlr-command-reactor)))))
          (vlr-added-p Reac))
   (progn
   (vlr-remove Reac)
   (princ "\n<< Reactor Deactivated >>"))

   (princ "\n** Reactor Not Running **"))

(princ))
      

 
将代码放入ACADDOC。lsp,以便在打开图形时运行。
 
您可以输入TIMEOFF以随时断开反应堆。
 

fcfcadd 发表于 2022-7-6 12:36:33

我会试一试,看看会发生什么。非常感谢你。如果这能奏效,这将为我节省大量的头痛和时间。

fcfcadd 发表于 2022-7-6 12:39:29

当我在autocad中打开一个图形时,一切都很好,但我看不到它将日志文件放在哪里
页: 1 [2]
查看完整版本: 时间日志