ygrzz 发表于 2007-2-5 04:39:00

lisp添加文件夹到"支持文件搜索路径"

;;; 设置路径===xyp1964<br/>(defun c:test041 (/ a pa lst ls1 path)<br/>    (setq a (getenv "ACAD")<br/>          pa (getstring "\n盘符 : ")   ; 要增加的路径,由用户自己改写<br/>          lst (list ":\block\a1" ":\block\a2" ":\block\a3" ":\bk\b1" ":\bk\b2" ":\bk\b3" ":\bk\pat" ;<br/>              )<br/>          ls1 (car lst)<br/>          path (strcat ";" pa ls1)<br/>          lst (vl-remove ls1 lst)<br/>    )<br/>    (while lst<br/>        (setq ls1 (car lst)<br/>              path (strcat path (strcat ";" pa ls1))<br/>              lst (vl-remove ls1 lst)<br/>        )<br/>    )<br/>    (setenv "ACAD" (strcat a path))<br/>    (getenv "ACAD")<br/>)<br/>;;; yfy2003<br/>;;; 添加文件夹到"支持文件搜索路径"中的指定位置<br/>(defun addSupportPath (dir pos / tmp c)<br/>    (setq tmp ""<br/>          c -1<br/>    )<br/>    (if (not pos)<br/>        (setq tmp (strcat (getenv "ACAD") ";" dir))<br/>        (mapcar<br/>            '(lambda (x)<br/>                 (setq tmp (if (= (setq c (1+ c))<br/>                                  pos<br/>                               )<br/>                               (strcat tmp ";" dir ";" x)<br/>                               (strcat tmp ";" x)<br/>                           )<br/>                 )<br/>             )<br/>            (parse (getenv "ACAD") ";")<br/>        )<br/>    )<br/>    (setenv "ACAD" tmp)<br/>    (princ)<br/>)<br/>;| 调用示例  (addSupportPath "D:\\myFolder" 2)<br/>参数文件夹路径及插入的位置( "ACAD"&lt;--- 一定要大写)<br/>注意:位置参数为空时将文件夹添加到路径最后。<br/>位置参数为0时将文件夹添加到路径最前端。  |;<br/>(defun Example_SupportPath ()          ; 这个范例返回<br/>                                       ; SupportPath的当前设定值,接着改变它的值,最后恢复初始值<br/>    (VL-LOAD-COM)<br/>    (setq AcadObject (vlax-get-acad-object)<br/>          AcadDocument (vla-get-ActiveDocument AcadObject)<br/>          mSpace (vla-get-ModelSpace AcadDocument)<br/>    )<br/>    (setq preferenceSel (vla-get-Preferences AcadObject))<br/>    (setq fileSel (vla-get-Files preferenceSel)) ; 取出当前的SupportPath值<br/>    (setq currSupportPath (vla-get-SupportPath fileSel))<br/>    (princ "SupportPath的值当前设定为: ")<br/>    (princ currSupportPath)<br/>    (princ "   SupportPath范例\\n")<br/>    (PROMPT "&lt;Enter&gt;进行:")<br/>    (VL-CMDF pause)                    ; 改变SupportPath的值<br/>    (vla-put-SupportPath fileSel "TestSupportPath")<br/>    (setq newSupportPath (vla-get-SupportPath fileSel))<br/>    (princ "SupportPath的新值设定为: ")<br/>    (princ newSupportPath)<br/>    (princ "   SupportPath范例\\n")<br/>    (PROMPT "&lt;Enter&gt;进行:")<br/>    (VL-CMDF pause)                    ; 将 SupportPath 重设为原来的值<br/>    (vla-put-SupportPath fileSel currSupportPath)<br/>    (vla-Regen AcadDocument acAllViewports)<br/>    (princ "SupportPath的值已经重设为: ")<br/>    (princ currSupportPath)<br/>    (princ "   SupportPath范例\\n")<br/>    (princ)<br/>)<br/><br/>

hai20110730 发表于 2012-3-4 17:28:11

另外补充一个错误,是“\\”不是“\”,不过还是非常谢谢你分享的源码。

daiguafan 发表于 2010-12-12 18:21:59

这个代表不错,谢谢

hai20110730 发表于 2012-3-4 17:24:25

我发现这几个程序中前2个都有错误,分号放错地方了,而且第一个那样写程序应该比较浪费,实际可以写的更省略一些的。

love_cq 发表于 2020-6-21 11:52:49

非常好的帖子,学习了。

paulpipi 发表于 2020-6-26 11:45:04

xiaojiajun160 发表于 2021-10-31 16:41:54

萌新表示值得研究

wzt 发表于 2022-12-20 14:43:51

; 添加文件夹到"支持文件搜索路径"中的指定位置   (parse (getenv "ACAD") ";") 不能执行 是什么原因

timmy521 发表于 2022-12-26 15:35:07

好东西,谢谢

流动的清泉 发表于 2023-11-5 21:35:23

没有 parse 子命令
页: [1]
查看完整版本: lisp添加文件夹到"支持文件搜索路径"