找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 635|回复: 1

[每日一码] 线型加载函数

[复制链接]

已领礼包: 19个

财富等级: 恭喜发财

发表于 2018-2-26 14:48:02 | 显示全部楼层 |阅读模式

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

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

×
  1. ;;;====================[ Linetype-load.lsp ]=======================
  2. ;;; Author: Copyright? 2008 Charles Alan Butler
  3. ;;; Version:  1.0 July 9, 2008
  4. ;;; Purpose:  function to load a list of linetypes
  5. ;;; Sub_Routines: -None
  6. ;;; Requirements: (Linetype-load lt-list (list "cab.lin"))
  7. ;;; The first argument is a list of list containing the linetype name,
  8. ;;; the preferred linetype file to search, this may be nil or missing if <reload-flag> is missing
  9. ;;; and a t/nil flag to reload an existing linetype, this may be nil or missing
  10. ;;;'((<lt-list> <lt-file-name> <reload-flag>)...)
  11. ;;; <lt-list> (("hidden" "acad.lin" <lt-load-flag>)("dashed" "acad.lin") ...)
  12. ;;; <lt-file-name> Optional, name of a LT file "lt-file01.lin", may be nil or missing if <reload-flag> is missing
  13. ;;; <reload-flag> Optional, T / nil t=reload the linetype even if it exist in the DWG
  14. ;;;   default for missing flag is nil and will not reload an existing linetype
  15. ;;; Valid list are '((<lt-list>) (<lt-list> <lt-file-name>) (<lt-list> <lt-file-name> <reload-flag>))
  16. ;;;
  17. ;;; Second argument is a list of linetype files that will be searched after the preferred file if
  18. ;;; the preferred file fails. This argument may be nil. The default ACAD LT file is always searched last.
  19. ;;; <file-list> ("lt-file01.lin" "lt-file02.lin" ...)
  20. ;;;
  21. ;;; Returns: nil if successful else a list of failed linetype names
  22. ;;;==========================================================

  23. (defun Linetype-load (lt-list   ; '((<lt-list> <lt-file-name> <reload-flag>)...)
  24.                       file-list ; '("lt-file01.lin" "lt-file02.lin" ...)
  25.                       / lt-data ltypes fname ltname def-ltfile tmp-file-list
  26.                       lt-loaded reload-flag idx err result)
  27.   (vl-load-com)
  28.   (setq ltypes (vla-get-linetypes
  29.                  (vla-get-activedocument (vlax-get-acad-object))))
  30.   ;;  set a default linetype file
  31.   (if (zerop (getvar "measurement"))
  32.     (setq def-ltfile "acad.lin")
  33.     (setq def-ltfile "acadiso.lin")
  34.   )
  35.   ;; load the linetypes
  36.   (foreach lt-data lt-list
  37.     (setq ltname (car lt-data)
  38.           fname  (cadr lt-data)
  39.           reload-flag (caddr lt-data)
  40.     )
  41.     (setq lt-loaded (tblsearch "ltype" ltname)) ; does the LineType exist in the DWG
  42.     (if file-list
  43.       (if (not (vl-position (strcase def-ltfile) (mapcar 'strcase file-list)))
  44.         (setq file-list (append file-list (list def-ltfile)))
  45.       )
  46.       (setq file-list (list def-ltfile))
  47.     )
  48.     (cond
  49.       ((and (not reload-flag) lt-loaded)
  50.        (prompt (strcat "\nLinetype " ltname " already loaded."))
  51.        ;;  stop here and do not reload the linetype
  52.       )
  53.       ;; test a specific linetype file, never stops here though
  54.       ((and fname (not (findfile fname))
  55.        (princ (strcat "\nCan not fine file " fname))
  56.        (setq fname nil))
  57.       )
  58.       (t ; Try & load linetype from file list, quit if loaded OK
  59.        (if (and fname ; add it to the file list as first choice
  60.                 (not (vl-position (strcase fname) (mapcar 'strcase file-list))))
  61.          (setq tmp-file-list (cons fname file-list))
  62.          (setq tmp-file-list file-list)
  63.        )
  64.        (setq idx 0)
  65.        ;;  loop until LT is loaded or out of file choices
  66.        (while (and
  67.                 (< idx (length tmp-file-list))
  68.                 (vl-catch-all-error-p
  69.                   (setq err (vl-catch-all-apply
  70.                               'vla-load (list ltypes ltname (nth idx tmp-file-list)))))
  71.                 )
  72.          (setq idx (1+ idx))
  73.        )
  74.        (cond  ; Report status of Load Attempt
  75.          ((vl-catch-all-error-p err)
  76.           (prompt (strcat "\n" (vl-catch-all-error-message err) " " ltname))
  77.           (setq result (cons ltname result))
  78.          )
  79.          ((vla-item ltypes ltname)
  80.           (prompt (strcat "\nLinetype " ltname " loaded from file " (nth idx tmp-file-list) "."))
  81.          )
  82.          (t
  83.           (prompt (strcat "\nError Linetype " ltname " not loaded."))
  84.           (setq result (cons ltname result))
  85.          )
  86.        )
  87.       )
  88.     )
  89.   )
  90.   result ; return a list of failed linetype names
  91. )



测试代码:

  1. (defun c:tt(/ lt-list fail-list)
  2.   (setq lt-list '(("hidden" "acad.lin")
  3.                   ("Very Fine Dot")
  4.                   ("batting")
  5.                   ("center" "acad.lin" t)
  6.                   ("border" "acad.lin")
  7.                   ("dot" "acad.lin")
  8.                   ("tracks" "C:\\l-type\\Ln.lin")
  9.                   ("phantom" "C:\\l-type\\Ln.lin")
  10.                   ("xyz" "cab.lin")
  11.                  )
  12.   )
  13.   (setq fail-list (Linetype-load lt-list (list "cab.lin")))
  14.   (if  fail-list
  15.     (print "Failed to load linetypes:")
  16.   )
  17.   (mapcar 'print fail-list)
  18.   (princ)
  19. )


评分

参与人数 1D豆 +5 收起 理由
muwind + 5 很给力!经验;技术要点;资料分享奖!

查看全部评分

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

已领礼包: 6468个

财富等级: 富甲天下

发表于 2018-2-27 00:01:08 | 显示全部楼层
沙发,谢谢分享。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-18 05:58 , Processed in 0.159416 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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