乐筑天下

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

[编程交流] 将每个层保存在单独的

[复制链接]

1

主题

6

帖子

5

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 17:30:18 | 显示全部楼层

我下载了。应该这样做的vlx文件(kpblc答案),在Acad中上传了应用程序(这是我应该做的吗?)。。。不知道下一步该怎么办!!
请再给我一点帮助。。。
泽维尔
LAY2DWG。拉链
回复

使用道具 举报

1

主题

6

帖子

5

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 17:33:01 | 显示全部楼层
好的,我找到了如何让它工作!(加载vlx,而不是键入命令“lay2dwg”)太简单了!这正是我需要的!
感谢所有人,特别感谢kpblc!
泽维尔
回复

使用道具 举报

dkn

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 17:37:31 | 显示全部楼层
 
我该怎么做才能让它工作呢?我将代码保存在一个txt文件中,然后将其重命名为。lsp,在autocad 2007中自动加载,但现在呢?我搞不懂命令
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-5 17:40:37 | 显示全部楼层
 
1.Tools>AutoLISP>Load。。。(也可以添加到“启动套件”中,以便在每个打开的文件中自动加载)。
 
2.在坐标系中键入lsave。
回复

使用道具 举报

0

主题

3

帖子

3

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 17:43:18 | 显示全部楼层
你好
是否也可以将活动层(on)保存在一个文件中?
 
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:45:59 | 显示全部楼层
试一试,添加了更多错误捕捉,以允许已经存在的文件名。
 
  1. ;;---------------------=={ Layer 2 DWG }==--------------------;;
  2. ;;                                                            ;;
  3. ;;  WBlocks all active layers to separate drawings, saved to  ;;
  4. ;;  the specified directory                                   ;;
  5. ;;------------------------------------------------------------;;
  6. ;;  Author: Lee McDonnell, 2010                               ;;
  7. ;;                                                            ;;
  8. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  9. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  10. ;;------------------------------------------------------------;;
  11. (defun c:Layer2DWG ( / *error* _UniqueFilename _UniqueItem _LayerList doc docname SelSets Path ss )
  12. (vl-load-com)
  13. ;; © Lee Mac 2010
  14. (defun *error* ( msg )
  15.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  16.        (princ (strcat "\n** Error: " msg " **")))
  17.    (princ)
  18. )
  19. (defun _UniqueFileName ( seed )
  20.    (
  21.      (lambda ( i / filename )
  22.        (if (findfile (setq filename (strcat seed ".dwg")))
  23.          (while (findfile (setq filename (strcat seed "(" (itoa (setq i (1+ i))) ").dwg"))))
  24.        )
  25.        filename
  26.      )
  27.      1
  28.    )
  29. )
  30. (defun _UniqueItem ( collection seed )
  31.    (
  32.      (lambda ( i )
  33.        (while (LM:Itemp collection (strcat seed (itoa (setq i (1+ i))))))
  34.        (strcat seed (itoa i))
  35.      )
  36.      0
  37.    )
  38. )
  39. (defun _LayerList ( doc / l )
  40.    (vlax-for layer (vla-get-layers doc)
  41.      (if
  42.        (not
  43.          (or
  44.            (eq :vlax-false (vla-get-layeron layer))
  45.            (wcmatch (vla-get-name layer) "*|*")
  46.          )
  47.        )
  48.        (setq l (cons (vla-get-name layer) l))
  49.      )
  50.    )
  51.    (reverse l)
  52. )
  53. (setq doc     (vla-get-ActiveDocument (vlax-get-acad-object))
  54.        docname (vl-filename-base (vla-get-Name doc))
  55.        SelSets (vla-get-SelectionSets doc))
  56. (if (setq Path (LM:DirectoryDialog "Select Directory for New Files" nil 0))
  57.    (progn
  58.      (setq ss (vla-Add SelSets (_UniqueItem SelSets "LayerSave")))
  59.      
  60.      (mapcar
  61.        (function
  62.          (lambda ( layer )
  63.            (LM:DXF->Variants (list (cons 8 layer)) 'typ 'val)
  64.            (vla-Select ss acSelectionSetAll nil nil typ val)
  65.            (if (not (zerop (vla-get-Count ss)))
  66.              (progn
  67.                (vla-WBlock doc (_UniqueFilename (strcat Path "\" docname "_" layer)) ss)
  68.                (princ (strcat "\n>>> Extracted Layer: " layer))
  69.              )
  70.              (princ (strcat "\n[ Nothing Found on Layer: " layer " ]"))
  71.            )
  72.            (vla-clear ss)            
  73.          )
  74.        )
  75.        (_LayerList doc)
  76.      )
  77.      (vl-catch-all-apply 'vla-delete (list ss))
  78.    )
  79.    (princ "\n*Cancel*")
  80. )
  81. (princ)
  82. )
  83. ;;-------------------=={ Directory Dialog }==-----------------;;
  84. ;;                                                            ;;
  85. ;;  Displays a dialog prompting the user to select a folder   ;;
  86. ;;------------------------------------------------------------;;
  87. ;;  Author: Lee McDonnell, 2010                               ;;
  88. ;;                                                            ;;
  89. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  90. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  91. ;;------------------------------------------------------------;;
  92. ;;  Arguments:                                                ;;
  93. ;;  msg  - message to display at top of dialog                ;;
  94. ;;  dir  - root directory (or nil)                            ;;
  95. ;;  flag - bit coded flag specifying dialog display settings  ;;
  96. ;;------------------------------------------------------------;;
  97. ;;  Returns:  Selected folder filepath, else nil              ;;
  98. ;;------------------------------------------------------------;;
  99. (defun LM:DirectoryDialog ( msg dir flag / Shell Fold FObj Path ac )
  100. ;; © Lee Mac 2010
  101. (setq Shell (vla-getInterfaceObject (setq ac (vlax-get-acad-object)) "Shell.Application")
  102.        Fold  (vlax-invoke-method Shell 'BrowseForFolder (vla-get-HWND ac) msg flag dir))
  103. (vlax-release-object Shell)
  104. (if Fold
  105.    (progn
  106.      (setq FObj (vlax-get-property Fold 'Self))
  107.      (setq Path (vlax-get-property FObj 'Path))
  108.      (vlax-release-object Fold)
  109.      (vlax-release-object FObj)
  110.      
  111.      (and (= "\" (substr Path (strlen Path)))
  112.           (setq Path (substr Path 1 (1- (strlen Path)))))
  113.    )
  114. )
  115. Path
  116. )
  117. ;;------------------=={ Safearray Variant }==-----------------;;
  118. ;;                                                            ;;
  119. ;;  Creates a populated Safearray Variant of a specified      ;;
  120. ;;  data type                                                 ;;
  121. ;;------------------------------------------------------------;;
  122. ;;  Author: Lee McDonnell, 2010                               ;;
  123. ;;                                                            ;;
  124. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  125. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  126. ;;------------------------------------------------------------;;
  127. ;;  Arguments:                                                ;;
  128. ;;  datatype - variant type enum (eg vlax-vbDouble)           ;;
  129. ;;  data     - list of static type data                       ;;
  130. ;;------------------------------------------------------------;;
  131. ;;  Returns:  VLA Variant Object of type specified            ;;
  132. ;;------------------------------------------------------------;;
  133. (defun LM:SafearrayVariant ( datatype data )
  134. ;; © Lee Mac 2010
  135. (vlax-make-variant
  136.    (vlax-safearray-fill
  137.      (vlax-make-safearray datatype
  138.        (cons 0 (1- (length data)))
  139.      )
  140.      data
  141.    )   
  142. )
  143. )
  144. ;;------------------=={ DXF->Variants }==---------------------;;
  145. ;;                                                            ;;
  146. ;;  Converts a DXF List to Type and Value Variants            ;;
  147. ;;------------------------------------------------------------;;
  148. ;;  Author: Lee McDonnell, 2010                               ;;
  149. ;;                                                            ;;
  150. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  151. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  152. ;;------------------------------------------------------------;;
  153. ;;  Arguments:                                                ;;
  154. ;;  lst  - DXF List                                           ;;
  155. ;;  *typ - a quoted symbol (other than *typ) to house variant ;;
  156. ;;  *val - a quoted symbol (other than *val) to house variant ;;
  157. ;;------------------------------------------------------------;;
  158. (defun LM:DXF->Variants ( lst *typ *val)
  159. ;; © Lee Mac 2010
  160. (set *typ (LM:SafearrayVariant vlax-vbInteger (mapcar 'car lst)))
  161. (set *val
  162.    (LM:SafearrayVariant vlax-vbVariant
  163.      (mapcar
  164.       '(lambda ( data )
  165.          (if (listp (setq data (cdr data)))
  166.            (vlax-3D-point data)
  167.            (vlax-make-variant data)
  168.          )
  169.        )
  170.       lst      
  171.      )
  172.    )
  173. )
  174. )
  175. ;;-----------------------=={ Itemp }==------------------------;;
  176. ;;                                                            ;;
  177. ;;  Retrieves the item with index 'item' if present in the    ;;
  178. ;;  specified collection, else nil                            ;;
  179. ;;------------------------------------------------------------;;
  180. ;;  Author: Lee McDonnell, 2010                               ;;
  181. ;;                                                            ;;
  182. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  183. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  184. ;;------------------------------------------------------------;;
  185. ;;  Arguments:                                                ;;
  186. ;;  coll - the VLA Collection Object                          ;;
  187. ;;  item - the index of the item to be retrieved              ;;
  188. ;;------------------------------------------------------------;;
  189. ;;  Returns:  the VLA Object at the specified index, else nil ;;
  190. ;;------------------------------------------------------------;;
  191. (defun LM:Itemp ( coll item )
  192. ;; © Lee Mac 2010
  193. (if
  194.    (not
  195.      (vl-catch-all-error-p
  196.        (setq item
  197.          (vl-catch-all-apply
  198.            (function vla-item) (list coll item)
  199.          )
  200.        )
  201.      )
  202.    )
  203.    item
  204. )
  205. )
回复

使用道具 举报

0

主题

3

帖子

3

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 17:49:14 | 显示全部楼层
谢谢你的快速回答。你的例行公事很有用!!
还有一个问题:是否可以将图层保存在一个dwg文件中?
 
再次感谢您的帮助!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:52:31 | 显示全部楼层
 
不客气。
 
将图层保存在一个dwg文件中-当然这就是您开始的内容?
回复

使用道具 举报

0

主题

3

帖子

3

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 17:57:53 | 显示全部楼层
 
不完全是!我有几个层(DXF文件使48 MB约60层)。我的任务是选择房间、出口等等。所以我只需要激活我修改/添加的图层,并将其保存为DXF文件。
 
你的程序完成了这项工作,但每个层都有一个文件。这是我第一次接触AutoCAD,因此我仍然没有使用is或AutoLisp的经验。所以我为我的新问题道歉!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:59:50 | 显示全部楼层
试一试:
 
  1. ;;--------------------=={ Layers 2 DWG }==--------------------;;
  2. ;;                                                            ;;
  3. ;;  WBlocks all active layers to a separate drawing, as       ;;
  4. ;;  specified by the user                                     ;;
  5. ;;------------------------------------------------------------;;
  6. ;;  Author: Lee McDonnell, 2010                               ;;
  7. ;;                                                            ;;
  8. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  9. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  10. ;;------------------------------------------------------------;;
  11. (defun c:Layers2DWG ( / *error* _UniqueItem _LayerList doc docname SelSets file ss )
  12. (vl-load-com)
  13. ;; © Lee Mac 2010
  14. (defun *error* ( msg )
  15.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  16.        (princ (strcat "\n** Error: " msg " **")))
  17.    (princ)
  18. )
  19. (defun _UniqueItem ( collection seed )
  20.    (
  21.      (lambda ( i )
  22.        (while (LM:Itemp collection (strcat seed (itoa (setq i (1+ i))))))
  23.        (strcat seed (itoa i))
  24.      )
  25.      0
  26.    )
  27. )
  28. (defun _LayerList ( doc / l )
  29.    (vlax-for layer (vla-get-layers doc)
  30.      (if
  31.        (not
  32.          (or
  33.            (eq :vlax-false (vla-get-layeron layer))
  34.            (wcmatch (vla-get-name layer) "*|*")
  35.          )
  36.        )
  37.        (setq l (cons (vla-get-name layer) l))
  38.      )
  39.    )
  40.    (reverse l)
  41. )
  42. (setq doc     (vla-get-ActiveDocument (vlax-get-acad-object))
  43.        docname (vl-filename-base (vla-get-Name doc))
  44.        SelSets (vla-get-SelectionSets doc))
  45. (if (setq file (getfiled "Create Output File" "" "dwg" 1))
  46.    (progn
  47.      (setq ss (vla-Add SelSets (_UniqueItem SelSets "LayerSave")))
  48.      (LM:DXF->Variants (list (cons 8 (LM:lst->str (_LayerList doc) ","))) 'typ 'val)
  49.      (vla-Select ss acSelectionSetAll nil nil typ val)
  50.      (if (not (zerop (vla-get-Count ss))) (vla-WBlock doc file ss))
  51.      (vl-catch-all-apply 'vla-delete (list ss))
  52.    )
  53.    (princ "\n*Cancel*")
  54. )
  55. (princ)
  56. )
  57. ;;------------------=={ Safearray Variant }==-----------------;;
  58. ;;                                                            ;;
  59. ;;  Creates a populated Safearray Variant of a specified      ;;
  60. ;;  data type                                                 ;;
  61. ;;------------------------------------------------------------;;
  62. ;;  Author: Lee McDonnell, 2010                               ;;
  63. ;;                                                            ;;
  64. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  65. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  66. ;;------------------------------------------------------------;;
  67. ;;  Arguments:                                                ;;
  68. ;;  datatype - variant type enum (eg vlax-vbDouble)           ;;
  69. ;;  data     - list of static type data                       ;;
  70. ;;------------------------------------------------------------;;
  71. ;;  Returns:  VLA Variant Object of type specified            ;;
  72. ;;------------------------------------------------------------;;
  73. (defun LM:SafearrayVariant ( datatype data )
  74. ;; © Lee Mac 2010
  75. (vlax-make-variant
  76.    (vlax-safearray-fill
  77.      (vlax-make-safearray datatype
  78.        (cons 0 (1- (length data)))
  79.      )
  80.      data
  81.    )   
  82. )
  83. )
  84. ;;------------------=={ DXF->Variants }==---------------------;;
  85. ;;                                                            ;;
  86. ;;  Converts a DXF List to Type and Value Variants            ;;
  87. ;;------------------------------------------------------------;;
  88. ;;  Author: Lee McDonnell, 2010                               ;;
  89. ;;                                                            ;;
  90. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  91. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  92. ;;------------------------------------------------------------;;
  93. ;;  Arguments:                                                ;;
  94. ;;  lst  - DXF List                                           ;;
  95. ;;  *typ - a quoted symbol (other than *typ) to house variant ;;
  96. ;;  *val - a quoted symbol (other than *val) to house variant ;;
  97. ;;------------------------------------------------------------;;
  98. (defun LM:DXF->Variants ( lst *typ *val)
  99. ;; © Lee Mac 2010
  100. (set *typ (LM:SafearrayVariant vlax-vbInteger (mapcar 'car lst)))
  101. (set *val
  102.    (LM:SafearrayVariant vlax-vbVariant
  103.      (mapcar
  104.       '(lambda ( data )
  105.          (if (listp (setq data (cdr data)))
  106.            (vlax-3D-point data)
  107.            (vlax-make-variant data)
  108.          )
  109.        )
  110.       lst      
  111.      )
  112.    )
  113. )
  114. )
  115. ;;-----------------------=={ Itemp }==------------------------;;
  116. ;;                                                            ;;
  117. ;;  Retrieves the item with index 'item' if present in the    ;;
  118. ;;  specified collection, else nil                            ;;
  119. ;;------------------------------------------------------------;;
  120. ;;  Author: Lee McDonnell, 2010                               ;;
  121. ;;                                                            ;;
  122. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  123. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  124. ;;------------------------------------------------------------;;
  125. ;;  Arguments:                                                ;;
  126. ;;  coll - the VLA Collection Object                          ;;
  127. ;;  item - the index of the item to be retrieved              ;;
  128. ;;------------------------------------------------------------;;
  129. ;;  Returns:  the VLA Object at the specified index, else nil ;;
  130. ;;------------------------------------------------------------;;
  131. (defun LM:Itemp ( coll item )
  132. ;; © Lee Mac 2010
  133. (if
  134.    (not
  135.      (vl-catch-all-error-p
  136.        (setq item
  137.          (vl-catch-all-apply
  138.            (function vla-item) (list coll item)
  139.          )
  140.        )
  141.      )
  142.    )
  143.    item
  144. )
  145. )
  146. ;;-------------------=={ List to String }==-------------------;;
  147. ;;                                                            ;;
  148. ;;  Constructs a string from a list of strings separating     ;;
  149. ;;  each element by a specified delimiter                     ;;
  150. ;;------------------------------------------------------------;;
  151. ;;  Author: Lee McDonnell, 2010                               ;;
  152. ;;                                                            ;;
  153. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  154. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  155. ;;------------------------------------------------------------;;
  156. ;;  Arguments:                                                ;;
  157. ;;  lst - a list of strings to process                        ;;
  158. ;;  del - delimiter by which to separate each list element    ;;
  159. ;;------------------------------------------------------------;;
  160. ;;  Returns:  String containing each string in the list       ;;
  161. ;;------------------------------------------------------------;;
  162. (defun LM:lst->str ( lst del )
  163. ;; © Lee Mac 2010
  164. (if (cdr lst)
  165.    (strcat (car lst) del (LM:lst->str (cdr lst) del))
  166.    (car lst)
  167. )
  168. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 13:13 , Processed in 0.846846 second(s), 70 queries .

© 2020-2025 乐筑天下

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