找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 21|回复: 0

[系统] (XD::VAR:GetRegTrustedPathKey)获取AutoCAD当前配置文件中“受信任路径”(TrustedPat

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 4 天前 | 显示全部楼层 |阅读模式
函数发布
函数名称: XD::VAR:GetRegTrustedPathKey
调用格式: (XD::VAR:GetRegTrustedPathKey profile)
参数说明: profile --- 配置的名字
返回值:
函数简介: 获取AutoCAD当前配置文件中“受信任路径”(TrustedPaths)的注册表键路径和值名称
函数来源: 原创
函数作者: newer
适用版本: 不限 
最后更新时间: 2025-12-16
备注: -
演示图片: -

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

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

×
本帖最后由 newer 于 2025-12-16 19:01 编辑

  1. (defun XD::VAR:GetRegTrustedPathKey (profile / software)
  2.   (setq software (strcase (getvar "product") t))
  3.   (if (not (xd::var:isgstarcad))
  4.        (list
  5.          (strcat "HKEY_CURRENT_USER\\"
  6.                  (vlax-product-key)
  7.                  "\\Profiles\\"
  8.                  profile
  9.                  "\\Variables"
  10.          )
  11.          "Trustedpaths"
  12.        )
  13.   )
  14. )


  1. (defun XD::VAR:ISGStarCAD ()
  2.   (= (strcase (getvar "product")) "GSTARCAD")
  3. )


示例1:基本用法用法例子:
  1. ;; 获取当前配置的受信任路径注册表信息
  2. (setq current-profile (getvar "cprofile"))  ; 获取当前配置文件名
  3. (setq reg-info (XD::VAR:GetRegTrustedPathKey current-profile))

  4. ;; 输出结果
  5. (if reg-info
  6.   (progn
  7.     (princ "\n注册表键路径: ") (princ (car reg-info))
  8.     (princ "\n值名称: ") (princ (cadr reg-info))
  9.   )
  10.   (princ "\n当前为浩辰CAD,不支持此操作")
  11. )


示例2:读取受信任路径
  1. ;; 读取当前CAD的受信任路径设置
  2. (defun GetTrustedPaths (/ profile reg-info paths)
  3.   (setq profile (getvar "cprofile"))  ; 获取当前配置
  4.   (setq reg-info (XD::VAR:GetRegTrustedPathKey profile))
  5.   
  6.   (if reg-info
  7.     (progn
  8.       (setq paths (vl-registry-read (car reg-info) (cadr reg-info)))
  9.       (princ (strcat "\n当前受信任路径: " (if paths paths "<未设置>")))
  10.       paths  ; 返回路径字符串
  11.     )
  12.     (progn
  13.       (princ "\n浩辰CAD使用不同机制管理受信任路径")
  14.       nil
  15.     )
  16.   )
  17. )

;; 使用
(setq trusted-paths (GetTrustedPaths))


示例3:设置受信任路径
  1. ;; 添加路径到受信任列表
  2. (defun AddTrustedPath (new-path / profile reg-info current-paths new-paths)
  3.   (setq profile (getvar "cprofile"))
  4.   (setq reg-info (XD::VAR:GetRegTrustedPathKey profile))
  5.   
  6.   (if (not reg-info)
  7.     (progn
  8.       (princ "\n错误:不支持当前CAD版本")
  9.       (return nil)
  10.     )
  11.   )
  12.   
  13.   ;; 获取现有路径
  14.   (setq current-paths (vl-registry-read (car reg-info) (cadr reg-info)))
  15.   
  16.   ;; 构建新路径(分号分隔)
  17.   (cond
  18.     ((not current-paths)  ; 如果还没有设置
  19.       (setq new-paths new-path)
  20.     )
  21.     ((not (wcmatch (strcase current-paths) (strcat "*" (strcase new-path) "*")))
  22.       ;; 如果新路径不在现有路径中
  23.       (setq new-paths (strcat current-paths ";" new-path))
  24.     )
  25.     (T  ; 路径已存在
  26.       (setq new-paths current-paths)
  27.     )
  28.   )
  29.   
  30.   ;; 写入注册表
  31.   (if (vl-registry-write (car reg-info) (cadr reg-info) new-paths)
  32.     (progn
  33.       (princ (strcat "\n已添加受信任路径: " new-path))
  34.       T
  35.     )
  36.     (progn
  37.       (princ "\n写入注册表失败")
  38.       nil
  39.     )
  40.   )
  41. )

;; 使用:添加当前目录到受信任路径
(AddTrustedPath (getvar "dwgprefix"))

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

本版积分规则

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

GMT+8, 2025-12-20 00:17 , Processed in 0.177494 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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