这是可行的。我做过这样的事。
但有几件事你必须安排。
-您需要有一个lisp文件,该文件在图形打开时自动加载,然后自动执行该功能。
因此,您必须以某种方式区分哪些文件应该自动执行该功能,哪些不应该。例如,您可以给出一个文件夹列表。如果图形位于该文件夹中,则执行该功能。
自动加载lisp文件:
https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/Automatically-load-AutoLISP-routines.html
这就像:
- ;; file "paste_text.lsp"
- (setq folders_to_autolaud (list
- "c:\\myAutocadfiles\\demo\"
- "c:\\myAutocadfiles\\demo2\"
- ))
- (defun paste_text (/)
- ;; do the pasting here
- ;; finish by closing the file
- (command-s "._close" "_y")
- )
- (if (member (getvar "dwgprefix") folders_to_autolaud)
- (paste_text)
- )
然后使用主文件加载该文件并执行命令OFPT
- ;; file "open_files_and_paste_text.lsp"
- (setq files_path "c:\\myAutocadfiles\\demo\")
- (setq list_of_files (list
- "file1.dwg"
- "file2.dwg"
- "file3.dwg"
- ))
- (defun open_file (FileName ReadOnly / )
- (vla-Open
- (vla-get-Documents
- (vlax-get-Acad-Object)
- )
- FileName
- (if ReadOnly
- :vlax-true
- :vlax-false
- )
- )
- )
- (defun c:OFPT ( / i)
- (setq i 0)
- (repeat (length list_of_files)
- ;; iterate over all files
- (open_file (nth i list_of_files) nil)
- (setq i (+ i 1))
- )
- (princ)
- )
这只是总体思路。这不是一个完整的、有效的例子。
您可能需要一些机制来减缓文件的打开速度,或者分批执行。你不希望100个打开的标签都在同一时间积极地做事情。
任何人,请随意对此进行扩展。
如果我有时间的话,我会看看完整的例子 |