乐筑天下

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

[编程交流] 在多个Dra中列出图层

[复制链接]

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:17:22 | 显示全部楼层
这个怎么样?
 
  1. (defun c:CheckLayers (/ *error* ObjRelease DirDialog Get_Subs ObjectDBXDocument GetLayers Str-Make
  2.                        DBX DOCLST DWLST FILE FOLDER LAYER_LIST PATH SHELL)
  3. (vl-load-com)
  4. ;; Lee Mac  ~  15.01.10
  5. (defun *error* (msg)
  6.    (ObjRelease (list Shell dbx))
  7.    (and ofile (= (type ofile) 'FILE) (close ofile))
  8.    
  9.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  10.        (princ (strcat "\n** Error: " msg " **")))
  11.    (princ))
  12. (defun ObjRelease (lst)
  13.    (mapcar
  14.      (function
  15.        (lambda (x)
  16.          (if (and (eq (type x) 'VLA-OBJECT)
  17.                   (not (vlax-object-released-p x)))
  18.            (vl-catch-all-apply
  19.              (function vlax-release-object) (list x))))) lst))
  20. (defun DirDialog (msg dir flag / Shell Fold Path)
  21.    ;; Lee Mac  ~  07.06.09
  22.    
  23.    (setq Shell (vla-getInterfaceObject *acad "Shell.Application")
  24.          Fold  (vlax-invoke-method Shell 'BrowseForFolder
  25.                  (vla-get-HWND *acad) msg flag dir))
  26.    (vlax-release-object Shell)
  27.    
  28.    (if Fold
  29.      (progn
  30.        (setq Path (vlax-get-property
  31.                     (vlax-get-property Fold 'Self) 'Path))
  32.        (vlax-release-object Fold)
  33.       
  34.        (and (= "\" (substr Path (strlen Path)))
  35.             (setq Path (substr Path 1 (1- (strlen Path)))))))
  36.    
  37.    Path)
  38. (defun Get_Subs (folder / file) ;; CAB
  39.    (mapcar
  40.      (function
  41.        (lambda (x) (setq file (strcat folder "\" x))
  42.                    (cons file (apply (function append) (get_subs file)))))
  43.        (cddr (vl-directory-files folder nil -1))))
  44. (defun ObjectDBXDocument (/ acVer)
  45.    
  46.    (vla-GetInterfaceObject *acad
  47.      (if (< (setq acVer (atoi (getvar "ACADVER"))) 16) "ObjectDBX.AxDbDocument"
  48.        (strcat "ObjectDBX.AxDbDocument." (itoa acVer)))))
  49. (defun GetLayerProperties (doc / lst)
  50.    (vlax-for lay (vla-get-Layers doc)
  51.      (setq lst (cons
  52.                  (mapcar
  53.                    (function
  54.                      (lambda (property)
  55.                        (vl-princ-to-string
  56.                          (vlax-get-property lay property))))
  57.                    '(Name Color Linetype LineWeight))
  58.                  lst)))
  59.    
  60.    (vl-sort lst
  61.      (function
  62.        (lambda (a b) (< (car a) (car b))))))
  63. (defun Str-Make (lst del / Pad str x)
  64.    (defun Pad (pStr pDel Len)
  65.      (while (< (strlen pStr) Len)
  66.        (setq pStr (strcat pStr pDel)))
  67.      pStr)
  68.    
  69.    (setq str  (Pad (car lst) (chr 32) 30))
  70.    (foreach x (cdr lst)
  71.      (setq str (strcat Str Del (Pad x (chr 32) 30))))
  72.    
  73. str)
  74. (setq *acad (cond (*acad) ((vlax-get-acad-object)))
  75.        *doc  (cond (*doc ) ((vla-get-ActiveDocument *acad))))
  76. (or *def* (setq *def* "Yes"))
  77. (if (and (setq Path (DirDialog "Select Directory" nil 0))
  78.           (vl-file-directory-p Path)
  79.           (setq outfile (getfiled "Output File" "" "txt" 1)))
  80.    (progn
  81.      (initget "Yes No")
  82.      (setq *def* (cond ((getkword
  83.                           (strcat "\nProcess SubDirectories? <" *def* "> : "))) (*def*)))
  84.      (vlax-for doc (vla-get-Documents *acad)
  85.        (setq DocLst (cons (cons (vla-get-FullName doc) doc) DocLst)))
  86.      
  87.      (foreach dwg  (setq dwLst (apply (function append)
  88.                                       (vl-remove 'nil
  89.                                         (mapcar
  90.                                           (function
  91.                                             (lambda (Path)
  92.                                               (mapcar
  93.                                                 (function
  94.                                                   (lambda (File)
  95.                                                     (strcat Path "\" File)))
  96.                                                 (vl-directory-files Path "*.dwg" 1))))
  97.                                           (append (list Path)
  98.                                                   (apply (function append)
  99.                                                          (if (= "YES" (strcase *def*))
  100.                                                            (Get_Subs Path))))))))
  101.        (setq dbx (cdr (assoc dwg DocLst)))        
  102.        (and (not dbx) (setq dbx (ObjectDBXDocument)))
  103.       
  104.        (if (not (vl-catch-all-error-p
  105.                    (vl-catch-all-apply
  106.                      (function vla-open) (list dbx dwg))))
  107.          (setq Layer_List (cons (cons dwg (GetLayerProperties dbx)) Layer_List))))
  108.      (princ (strcat "\n<< " (itoa (length dwLst)) " Drawings Processed >>")))
  109.    
  110.    (princ "*Cancel*"))
  111. (ObjRelease (list Shell dbx)) (gc) (gc)
  112. (if (and Layer_List
  113.          (setq ofile (open outfile "w")))
  114.    (progn
  115.      
  116.      (mapcar
  117.        (function
  118.          (lambda (x)
  119.            (write-line (car x) ofile)
  120.            (write-line (Str-Make '("Name" "Colour" "LineType" "LineWeight") (chr 32)) ofile)
  121.            (mapcar
  122.              (function
  123.                (lambda (y)
  124.                  (write-line
  125.                    (Str-Make y (chr 32)) ofile))) (cdr x))
  126.            
  127.            (write-line "\n" ofile)))
  128.        Layer_List)
  129.      (close ofile))
  130.    (princ "\n*Cancel*"))
  131. (princ))
回复

使用道具 举报

36

主题

183

帖子

151

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
185
发表于 2022-7-5 17:22:17 | 显示全部楼层
哦。。。真是太好了!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:23:28 | 显示全部楼层
这具有更好的间距功能:
 
  1. (defun c:CheckLayers (/ *error* ObjRelease DirDialog Get_Subs ObjectDBXDocument GetLayers Str-Make
  2.                        DBX DOCLST DWLST FILE FOLDER LAYER_LIST PATH SHELL)
  3. (vl-load-com)
  4. ;; Lee Mac  ~  15.01.10
  5. (defun *error* (msg)
  6.    (ObjRelease (list Shell dbx))
  7.    (and ofile (= (type ofile) 'FILE) (close ofile))
  8.    
  9.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  10.        (princ (strcat "\n** Error: " msg " **")))
  11.    (princ))
  12. (defun ObjRelease (lst)
  13.    (mapcar
  14.      (function
  15.        (lambda (x)
  16.          (if (and (eq (type x) 'VLA-OBJECT)
  17.                   (not (vlax-object-released-p x)))
  18.            (vl-catch-all-apply
  19.              (function vlax-release-object) (list x))))) lst))
  20. (defun DirDialog (msg dir flag / Shell Fold Path)
  21.    ;; Lee Mac  ~  07.06.09
  22.    
  23.    (setq Shell (vla-getInterfaceObject *acad "Shell.Application")
  24.          Fold  (vlax-invoke-method Shell 'BrowseForFolder
  25.                  (vla-get-HWND *acad) msg flag dir))
  26.    (vlax-release-object Shell)
  27.    
  28.    (if Fold
  29.      (progn
  30.        (setq Path (vlax-get-property
  31.                     (vlax-get-property Fold 'Self) 'Path))
  32.        (vlax-release-object Fold)
  33.       
  34.        (and (= "\" (substr Path (strlen Path)))
  35.             (setq Path (substr Path 1 (1- (strlen Path)))))))
  36.    
  37.    Path)
  38. (defun Get_Subs (folder / file) ;; CAB
  39.    (mapcar
  40.      (function
  41.        (lambda (x) (setq file (strcat folder "\" x))
  42.                    (cons file (apply (function append) (get_subs file)))))
  43.        (cddr (vl-directory-files folder nil -1))))
  44. (defun ObjectDBXDocument (/ acVer)
  45.    
  46.    (vla-GetInterfaceObject *acad
  47.      (if (< (setq acVer (atoi (getvar "ACADVER"))) 16) "ObjectDBX.AxDbDocument"
  48.        (strcat "ObjectDBX.AxDbDocument." (itoa acVer)))))
  49. (defun GetLayerProperties (doc / lst)
  50.    (vlax-for lay (vla-get-Layers doc)
  51.      (setq lst (cons
  52.                  (mapcar
  53.                    (function
  54.                      (lambda (property)
  55.                        (vl-princ-to-string
  56.                          (vlax-get-property lay property))))
  57.                    '(Name Color Linetype LineWeight))
  58.                  lst)))
  59.    
  60.    (vl-sort lst
  61.      (function
  62.        (lambda (a b) (< (car a) (car b))))))
  63. (defun Str-Make  (lst del / Pad str x i)
  64.    (setq i 10)
  65.    (defun Pad  (Str Del Len)
  66.      (while (>= (strlen Str) Len) (setq Len (+ Len 5)))
  67.      (while (< (strlen Str) Len)
  68.        (setq Str (strcat Str Del)))
  69.      Str)
  70.    (apply (function strcat)
  71.           (reverse
  72.             (cons (last lst)
  73.                   (mapcar
  74.                     (function
  75.                       (lambda ($str)
  76.                         (Pad $str del
  77.                              (setq i (abs (- 40 i))))))
  78.                     (cdr (reverse lst)))))))
  79.    
  80. (setq *acad (cond (*acad) ((vlax-get-acad-object)))
  81.        *doc  (cond (*doc ) ((vla-get-ActiveDocument *acad))))
  82. (or *def* (setq *def* "Yes"))
  83. (if (and (setq Path (DirDialog "Select Directory" nil 0))
  84.           (vl-file-directory-p Path)
  85.           (setq outfile (getfiled "Output File" "" "txt" 1)))
  86.    (progn
  87.      (initget "Yes No")
  88.      (setq *def* (cond ((getkword
  89.                           (strcat "\nProcess SubDirectories? <" *def* "> : "))) (*def*)))
  90.      (vlax-for doc (vla-get-Documents *acad)
  91.        (setq DocLst
  92.          (cons (cons (strcase (vla-get-FullName doc)) doc) DocLst)))
  93.      
  94.      (foreach dwg (setq dwLst (apply (function append)
  95.                                       (vl-remove 'nil
  96.                                         (mapcar
  97.                                           (function
  98.                                             (lambda (Path)
  99.                                               (mapcar
  100.                                                 (function
  101.                                                   (lambda (File)
  102.                                                     (strcat Path "\" File)))
  103.                                                 (vl-directory-files Path "*.dwg" 1))))
  104.                                           (append (list Path)
  105.                                                   (apply (function append)
  106.                                                          (if (= "YES" (strcase *def*))
  107.                                                            (Get_Subs Path))))))))
  108.        (setq dbx (cdr (assoc (strcase dwg) DocLst)))        
  109.        (and (not dbx) (setq dbx (ObjectDBXDocument)))
  110.       
  111.        (if (not (vl-catch-all-error-p
  112.                    (vl-catch-all-apply
  113.                      (function vla-open) (list dbx dwg))))
  114.          (setq Layer_List (cons (cons dwg (GetLayerProperties dbx)) Layer_List))
  115.          (setq Layer_List (cons (cons dwg '(("**Error Opening this Drawing **"))) Layer_List))))
  116.                
  117.      (princ (strcat "\n<< " (itoa (length dwLst)) " Drawings Processed >>")))
  118.    
  119.    (princ "*Cancel*"))
  120. (ObjRelease (list Shell dbx)) (gc) (gc)
  121. (if (and Layer_List
  122.          (setq ofile (open outfile "w")))
  123.    (progn
  124.      
  125.      (mapcar
  126.        (function
  127.          (lambda (x)
  128.            (write-line (car x) ofile)
  129.            (write-line (Str-Make '("Name" "Colour" "LineType" "LineWeight") (chr 32)) ofile)
  130.            (mapcar
  131.              (function
  132.                (lambda (y)
  133.                  (write-line
  134.                    (Str-Make y (chr 32)) ofile))) (cdr x))
  135.            
  136.            (write-line "\n" ofile)))
  137.        Layer_List)
  138.      (close ofile))
  139.    (princ "\n*Cancel*"))
  140. (princ))
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 17:31:47 | 显示全部楼层
这真是一部了不起的作品冲击:
李是你的超级粉丝。
重新播放代码为我节省了很多时间。但是我想知道你是否可以帮我把代码设置成忽略所有外部参照。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:35:01 | 显示全部楼层
 
谢谢你的客气话MihaiT,欢迎来到CADTutor。
 
这个线程包含一些非常旧的代码该程序后来发展成为我的图层提取器应用程序,它提供了从输出中包括/排除外部参照相关图层的选项。
 
我很高兴你发现代码很有用!
 
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-8-21 01:57 , Processed in 1.491609 second(s), 71 queries .

© 2020-2025 乐筑天下

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