newer 发表于 2025-12-16 18:54:38

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

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



(defun XD::VAR:GetRegTrustedPathKey (profile / software)
(setq software (strcase (getvar "product") t))
(if (not (xd::var:isgstarcad))
       (list
         (strcat "HKEY_CURRENT_USER\\"
               (vlax-product-key)
               "\\Profiles\\"
               profile
               "\\Variables"
         )
         "Trustedpaths"
       )
)
)



(defun XD::VAR:ISGStarCAD ()
(= (strcase (getvar "product")) "GSTARCAD")
)


示例1:基本用法用法例子:

;; 获取当前配置的受信任路径注册表信息
(setq current-profile (getvar "cprofile")); 获取当前配置文件名
(setq reg-info (XD::VAR:GetRegTrustedPathKey current-profile))

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


示例2:读取受信任路径


;; 读取当前CAD的受信任路径设置
(defun GetTrustedPaths (/ profile reg-info paths)
(setq profile (getvar "cprofile")); 获取当前配置
(setq reg-info (XD::VAR:GetRegTrustedPathKey profile))

(if reg-info
    (progn
      (setq paths (vl-registry-read (car reg-info) (cadr reg-info)))
      (princ (strcat "\n当前受信任路径: " (if paths paths "<未设置>")))
      paths; 返回路径字符串
    )
    (progn
      (princ "\n浩辰CAD使用不同机制管理受信任路径")
      nil
    )
)
)

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


示例3:设置受信任路径


;; 添加路径到受信任列表
(defun AddTrustedPath (new-path / profile reg-info current-paths new-paths)
(setq profile (getvar "cprofile"))
(setq reg-info (XD::VAR:GetRegTrustedPathKey profile))

(if (not reg-info)
    (progn
      (princ "\n错误:不支持当前CAD版本")
      (return nil)
    )
)

;; 获取现有路径
(setq current-paths (vl-registry-read (car reg-info) (cadr reg-info)))

;; 构建新路径(分号分隔)
(cond
    ((not current-paths); 如果还没有设置
      (setq new-paths new-path)
    )
    ((not (wcmatch (strcase current-paths) (strcat "*" (strcase new-path) "*")))
      ;; 如果新路径不在现有路径中
      (setq new-paths (strcat current-paths ";" new-path))
    )
    (T; 路径已存在
      (setq new-paths current-paths)
    )
)

;; 写入注册表
(if (vl-registry-write (car reg-info) (cadr reg-info) new-paths)
    (progn
      (princ (strcat "\n已添加受信任路径: " new-path))
      T
    )
    (progn
      (princ "\n写入注册表失败")
      nil
    )
)
)

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

bghyu 发表于 2025-12-25 14:10:44

:loveliness::victory::'(
页: [1]
查看完整版本: (XD::VAR:GetRegTrustedPathKey)获取AutoCAD当前配置文件中“受信任路径”(TrustedPat