乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: MarcoW

[编程交流] 需要代码帮助

[复制链接]

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 11:51:06 | 显示全部楼层
如果线型存在于多个中,也可以添加检查。林文件。例如,隐藏的线型,两者都存在于ACAD中。林和阿卡迪索。但是他们是不同的。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:56:16 | 显示全部楼层
这将打印找到的所有重复定义的列表:
 
  1. (defun lt_doups (/ StrBrk Path files lst tmp nl lLst)
  2. ;; String Breaker by Lee McDonnell
  3. (defun StrBrk (str chrc / pos lst)
  4.    (while (setq pos (vl-string-position chrc str))
  5.      (setq lst (cons (substr str 1 pos) lst)
  6.            str (substr str (+ pos 2))))
  7.    (reverse (cons str lst)))
  8. (foreach Path (vl-remove "" (StrBrk (getenv "ACAD") 59))
  9.    (and (setq files (vl-directory-files Path "*.lin" 1))
  10.         (setq lst   (append lst (mapcar (function (lambda (x) (strcat Path "\" x))) files)))))
  11. (foreach file lst
  12.    (setq tmp (open file "r"))
  13.    (while (setq nl (read-line tmp))
  14.      (and (eq "*"  (substr nl 1 1))
  15.           (setq llst (cons (cons (car (StrBrk (substr nl 2) 44))
  16.                                  (vl-filename-base file)) llst))))
  17.    (close tmp))
  18. (setq k -1)
  19. (foreach x
  20.    (vl-sort
  21.      (vl-remove-if-not
  22.        (function
  23.          (lambda (x / remove_nth)
  24.            (defun remove_nth (i lst / j)
  25.              (setq j -1)
  26.                (vl-remove-if
  27.                  (function
  28.                    (lambda (y)
  29.                      (eq i (setq j (1+ j))))) lst))
  30.            (vl-position (car x)
  31.              (mapcar (function car)
  32.                      (remove_nth (setq k (1+ k)) lLst))))) lLst)
  33.      (function (lambda (a b) (< (car a) (car b)))))
  34.    (print x)))
回复

使用道具 举报

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 11:56:42 | 显示全部楼层
快速代码李,一如既往,我建议提醒用户,如果存在重复,并让用户选择从中加载,因为他们是不同的,虽然相同的名称。如果用户仅使用acad,则当前代码没有问题。林。。只是一个建议,干得好…:-)
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 12:02:01 | 显示全部楼层
 
同意,我经常根据自己的需要使用:
  1. (defun ltype-load (ltyp)
  2. (if (not (tblsearch "ltype" ltyp))
  3. (command "._-linetype" "_l"  ltyp
  4. (findfile
  5. (if (= (getvar "measurement") 0)
  6. "acad.lin"
  7. "acadiso.lin")) ""))
  8. (princ)
  9. )

 
~'J'~
回复

使用道具 举报

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 12:04:59 | 显示全部楼层
 
 
很好的代码修复,谢谢。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:06:28 | 显示全部楼层
 
谢谢Wiz
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:09:29 | 显示全部楼层
 
也许有点像。。。
 
  1. (defun lt_load (ltname / StrBrk DCTAG F FILES FLAG FN L LLST LST NL PATH TFILE TMP)
  2. ;; String Breaker by Lee McDonnell
  3. (defun StrBrk (str chrc / pos lst)
  4.    (while (setq pos (vl-string-position chrc str))
  5.      (setq lst (cons (substr str 1 pos) lst)
  6.            str (substr str (+ pos 2))))
  7.    (reverse (cons str lst)))
  8. (foreach Path (vl-remove "" (StrBrk (getenv "ACAD") 59))
  9.    (and (setq files (vl-directory-files Path "*.lin" 1))
  10.         (setq lst   (append lst (mapcar (function (lambda (x) (strcat Path "\" x))) files)))))
  11. (foreach file lst
  12.    (setq tmp (open file "r"))
  13.    (while (setq nl (read-line tmp))
  14.      (and (eq "*"  (substr nl 1 1))
  15.           (eq (strcase ltname)
  16.               (setq l (strcase (car (StrBrk (substr nl 2) 44)))))
  17.           (setq llst (cons (cons l (strcat (vl-filename-base file) ".lin")) llst))))
  18.    (close tmp))
  19. (if lLst
  20.    (if (< 1 (length lLst))
  21.      (progn
  22.        (setq fn (open (setq tfile (vl-filename-mktemp "" "" ".dcl")) "w"))
  23.        (foreach str '("lt_dcl : dialog { label = "Select Load File"; spacer;"
  24.                       ": popup_list { alignment = centered; key = "flin"; } spacer; ok_cancel; } ")
  25.          (write-line str fn))
  26.        (close fn)
  27.        (if (and (<= 0 (setq dcTag (load_dialog tFile)))
  28.                 (new_dialog "lt_dcl" dcTag))
  29.          (progn
  30.            (start_list "flin")
  31.            (mapcar 'add_list (mapcar 'cdr lLst)) (end_list)
  32.            (setq f (car lLst))
  33.            (action_tile "flin"   "(setq f (nth (atoi $value) lLst))")
  34.            (action_tile "accept" "(done_dialog 1)")
  35.            (action_tile "cancel" "(done_dialog 0)")
  36.            (setq flag (start_dialog))
  37.            (unload_dialog dcTag)))
  38.        (vl-file-delete tfile))
  39.      (setq flag 1 f (car lLst))))
  40. (if (eq flag 1)
  41.    (vla-load
  42.      (vla-get-linetypes
  43.        (vla-get-ActiveDocument
  44.          (vlax-get-acad-object))) (car f) (cdr f)))
  45. (and (tblsearch "LTYPE" ltname)))

 
现在这对我来说很好(尽管这是一个混乱的;-|…)调用命令“createlayer”时。然后我把它们都填好,它就开始工作了。
 
但是如果我通过宏使用它,那么它确实可以工作,但层不能获得电流。
 
这是一个以前从未有过的例程,它在宏中的工作方式与在命令栏中的不同。宏位于工具选项板中,这可能就是问题所在。
 
谁能给我解释一下怎么解决这个问题?(因此,将从toolpalette中使用createlayer函数,以便将其设置为当前)。
 
提前谢谢。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:14:22 | 显示全部楼层
看起来李已经击败了我,但这里是我的搜索之一。lin文件位于支持搜索路径中。
 
它在搜索路径中搜索并查找。林文件,并生成一个文件列表,然后查看。
  1. (defun c:createlayer (/ ltname layname laycol cmdold lay)
  2. (vl-load-com)
  3. (command "-linetype" "s" "bylayer" ""); in case if not bylayer
  4. (setq ltname (getstring "\nPlease enter the name of the linetype: ")
  5.        layname (getstring "\nPlease enter the name of the layer: ")
  6.        laycol (getint "\nPlease enter the colour of the layer: ")
  7. layplot (getstring "\nDo you want the layer to be <Plot> or <Non plot>: ")
  8.        cmdold (getvar "CMDECHO"))
  9. (setvar "CMDECHO" 0)
  10. ;switch to timothy's code
  11. (STDLIB_LOAD_LINETYPE ltname)
  12. ;; Loading Linetype  ~ Another option to consider:
  13. (if (not (tblsearch "LTYPE" ltname))
  14.    (vla-load
  15.      (vla-get-Linetypes
  16.        (vla-get-ActiveDocument
  17.          (vlax-get-acad-object))) ltname "acadiso.lin"))
  18. ;; Layer Checking & Creation
  19. (if (not (tblsearch "LAYER" layname))
  20.    (command "_.-layer" "_M" layname "_L" ltname layname "_C" laycol layname "_P" layplot "" "")
  21.    (setvar "CLAYER" layname))
  22. ;; Reset CMDECHO
  23. (setvar "CMDECHO" cmdold)
  24. (setvar "CECOLOR" "bylayer")
  25. (princ))
  26. ;;; ------------------------------------------------------------------------
  27. ;;;    STDLIB_LOAD_LINETYPE.LSP
  28. ;;;
  29. ;;;    Copyright © December, 2008
  30. ;;;    Timothy G. Spangler
  31. ;;;
  32. ;;;    Permission to use, copy, modify, and distribute this software
  33. ;;;    for any purpose and without fee is hereby granted, provided
  34. ;;;    that the above copyright notice appears in all copies and
  35. ;;;    that both that copyright notice and the limited warranty and
  36. ;;;    restricted rights notice below appear in all supporting
  37. ;;;    documentation.
  38. ;;;
  39. ;;;    STDLIB_LOAD_LINETYPE
  40. ;;;
  41. ;;;   Description:
  42. ;;;   Called from a menu pulldown or rightclick menu
  43. ;;;  * (STDLIB_LOAD_LINETYPE <LINETYPE>)
  44. ;;;  <LINETYPE>   = STRING = Valid linetype
  45. ;;;
  46. ;;;   Returns:
  47. ;;;    T if found and loaded otherwise nil
  48. ;;;
  49. ;;; ------------------------------------------------------------------------
  50. ;;; MAIN FUNCTION ;;;;;;;;;;;;;;;;;;;;;;;;;
  51. (defun STDLIB_LOAD_LINETYPE (Linetype / OldCmdEcho LineFiles FullFile Found OpenFile CurrentLine LinePath Result)
  52. ;; Set system variables
  53. (setq OldCmdEcho (getvar "CMDECHO"))
  54. (setvar "CMDECHO" 0)
  55. ;; Load linetype
  56. (if (not (tblsearch "LTYPE" Linetype))
  57. (progn
  58.   ;; Check each search path for a .lin file
  59.   (foreach Path (STR->LIST (getenv "ACAD") ";")
  60.    (if (setq LineFiles (vl-directory-files Path "*.lin"))
  61.     (progn
  62.      (foreach File LineFiles
  63.       (setq FullFile (cons (strcat Path "\" File) FullFile))
  64.      )
  65.      (setq Found (cons Path Found))
  66.     )
  67.    )
  68.   )
  69.   ;; Read each line file found and check for the linetype
  70.   (foreach LineFile FullFile
  71.    (setq OpenFile (open LineFile "r"))
  72.    (while (setq CurrentLine (read-line OpenFile))
  73.     (if (wcmatch (strcase CurrentLine) (strcat "*" (strcase LineType) "*"))
  74.      (setq LinePath Linefile)
  75.     )
  76.    )
  77.    (close OpenFile)
  78.   )
  79.   ;; Load result
  80.   (if LinePath
  81.    (setq Result T)     
  82.    (setq Result nil)
  83.   )
  84. )
  85. )
  86. (if Result
  87. ;(command "-linetype" "load" Linetype LinePath "")
  88. (vl-cmdf "-linetype" "load" Linetype LinePath "")
  89. )
  90. ;; Reset system
  91. (setvar "CMDECHO" OldCmdEcho)
  92. ;; Send Result
  93. Result
  94. )
  95. (princ)
  96. ;;; ------------ STRING TO LIST SUB ROUTINE, CREATE A LIST FROM A STRING WITH DELIMETER
  97. (defun STR->LIST (Stg Del / CurChr PosCnt TmpLst TmpStr NewTmpLst)
  98. (setq PosCnt 1)
  99. (setq TmpStr "")
  100. (repeat (1+ (strlen Stg))
  101. (setq CurChr (substr Stg PosCnt 1))
  102. (if (= CurChr Del)
  103.   (progn
  104.    (setq TmpLst (cons TmpStr TmpLst))
  105.    (setq TmpStr "")
  106.   )
  107.   (setq TmpStr (strcat TmpStr CurChr))
  108. )
  109. (setq PosCnt (1+ PosCnt))
  110. )
  111. (if (/= TmpStr "")
  112. (setq TmpLst (cons TmpStr TmpLst))
  113. )
  114. (setq NewTmpLst (reverse TmpLst))
  115. NewTmpLst
  116. )
回复

使用道具 举报

59

主题

327

帖子

268

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
295
发表于 2022-7-6 12:15:38 | 显示全部楼层
回复

使用道具 举报

2

主题

182

帖子

180

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 12:21:35 | 显示全部楼层
Looks like LeeMac beat me to it already but here is one of my searches for all .lin files in the support search path.
 
Itterates thru the search path and look for .lin files and generate a list of files to then look thru.
  1. ( (lambda ( / )  (apply   ;; itterate thru the entire search path to look for .lin files   'append   (mapcar    '(lambda ( x / tmp-str)            (setq tmp-str (vl-directory-files x "*.lin" 1))            (if (and tmp-str (not (eq ";" x)))             (list              (strcat               x               "\"               (car tmp-str)))) )    ( (lambda (aStr delim)       (while         (setq pos (vl-string-search delim aStr 0))        (setq strList (cons (substr aStr 1 pos) strList)         strList (cons (substr aStr (1+ pos) (strlen delim)) strList)         aStr (substr aStr (+ pos (1+ (strlen delim)))))       )       (reverse (cons aStr strList)))      (getvar "ACADPREFIX") ";")))) )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-6 02:59 , Processed in 0.467987 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表