明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1057|回复: 6

添加默认搜索目录

[复制链接]
发表于 2020-7-13 18:10 | 显示全部楼层 |阅读模式
本帖最后由 jun353835273 于 2020-7-13 20:02 编辑

搜索了一下论坛全好像是用系统变量添加的,今天发现有现成的vla函数,分享给大家,方便关键词搜索,方便使用。
  1. (setq  addpath "c:\\test" )
  2. (setq Preferences
  3.        (vla-get-Files
  4.          (vla-get-Preferences
  5.            (vlax-get-Acad-Object)
  6.          )
  7.        )
  8. )
  9. (setq paths (vla-get-SupportPath Preferences)) ;获取搜索目录
  10. (vla-put-SupportPath Preferences (strcat(strcat paths ";" addpath))) ;设定搜索目录           



发表于 2020-7-13 19:42 | 显示全部楼层
vla添加默认搜索目录。
感谢分享!

评分

参与人数 1明经币 +1 收起 理由
yangchao2005090 + 1

查看全部评分

发表于 2020-7-13 22:29 | 显示全部楼层
(vla-get-SupportPath Preferences)好像等于 (getenv "ACAD" )
 楼主| 发表于 2020-7-14 07:55 | 显示全部楼层
muwind 发表于 2020-7-13 22:29
(vla-get-SupportPath Preferences)好像等于 (getenv "ACAD" )

是的,系统变量
发表于 2020-7-14 11:12 | 显示全部楼层
setenv 之类的命令,CAD不能实时反应出来,建议用Autolisp相关命令。楼主的语句少了个判断,比如已有该路径了,就不能再添加了。另外支持路径有先后关系,有冲突的文件时,优先级的控制等。
 楼主| 发表于 2020-7-14 14:29 | 显示全部楼层
G〆h 发表于 2020-7-14 11:12
setenv 之类的命令,CAD不能实时反应出来,建议用Autolisp相关命令。楼主的语句少了个判断,比如已有该路径 ...

只是给出的一种方法,需要的自己添加吧,
不是贴的完整的函数,不过也没有写
 楼主| 发表于 2020-7-15 09:03 | 显示全部楼层
居然翻到高飞鸟国外论坛发的
http://www.theswamp.org/index.php?topic=38073.msg430932#msg430932
  1. ;;; --------------------------------------------------------------------
  2. ;;; Function: Add a path and its subdirectories to AutoCAD support path.
  3. ;;; Highflybird  2011.4.25                                             
  4. ;;; --------------------------------------------------------------------

  5. (vl-load-com)
  6. (prompt "The command is: Test")
  7. (defun c:test(/ *Shell FSO Folder Path LastString LST OldSupportPath NewSupportPath)
  8.   ;; Search All the Subdirectories
  9.   (defun SearchPath (path / f n p Dirs)
  10.     (setq Dirs (vl-directory-files path nil -1))
  11.     (setq f (car Dirs))
  12.     (and (= f ".") (setq Dirs (cddr Dirs)))
  13.     (foreach n Dirs
  14.       (setq p (strcat Path n "\"))
  15.       (setq Lst (cons p Lst))
  16.       (SearchPath p)
  17.     )
  18.     lst
  19.   )

  20.   (setq *Shell (vlax-create-object "Shell.Application"))                ;Create a Shell Object to select folder       
  21.   (setq FSO (vlax-create-object "Scripting.FileSystemObject"))                ;Create a File system object to check the Folder.
  22.   (setq Folder
  23.     (vlax-invoke *Shell 'BrowseForFolder                                 ;Browse for folder
  24.       (vla-get-hwnd (vlax-get-acad-object))
  25.       "Select a Folder"
  26.       83
  27.     )
  28.   )

  29.   (if (and Folder
  30.            (setq Path (vlax-get (vlax-get Folder 'self) 'path))
  31.            (/= (vlax-invoke FSO 'FolderExists Path) 0)
  32.       )
  33.     (progn
  34.       (setq LastString (substr path (strlen path)))
  35.       (if (or (/= LastString "\") (/= LastString "/") )
  36.         (setq Path (strcat Path "\"))
  37.       )
  38.       (setq Lst (list Path))
  39.       (setq Lst (reverse (SearchPath Path)))
  40.       (setq OldSupportPath (getenv "ACAD"))                                ;Get old support path
  41.       ;;(setvar "USERS1" OldSupportPath)
  42.       (setq NewSupportPath OldSupportPath)
  43.       (foreach p Lst
  44.         (setq NewSupportPath (strcat NewSupportPath ";" p))
  45.       )
  46.       (setenv "ACAD" NewSupportPath)                                        ;set new support path
  47.     )
  48.   )
  49.   (and FSO (vlax-release-object FSO))
  50.   (and *SHELL (vlax-release-object *SHELL))
  51.   (princ)
  52. )

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-23 23:15 , Processed in 0.223702 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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