找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1116|回复: 6

[转贴]:DSX AutoLayer

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2003-7-25 12:56:42 | 显示全部楼层 |阅读模式

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

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

×

  1. ;;;*********************************************************
  2. ;;;*********************************************************
  3. (vl-load-com)
  4. (defun get-item        (collection item / result)
  5.   (cond
  6.     ((not
  7.        (vl-catch-all-error-p
  8.          (setq result
  9.                 (vl-catch-all-apply 'vla-item (list collection item))
  10.          )
  11.        )
  12.      )
  13.      result
  14.     )
  15.   )
  16. )
  17. (setq oAcad (vlax-get-acad-object)        ; acadapplication object
  18.       oDoc  (vla-get-activedocument oAcad) ; activedocument object
  19.       oLay  (vla-get-layers oDoc)        ; layers collection of activedocument
  20. )
  21. (defun rCmdLayer (reactor data / cmd)
  22.   (setq cmd (strcase (car data)))        ; get command name
  23.   (cond
  24.     ((wcmatch cmd "*HATCH")                ;is the command "*hatch"?
  25.      (rCmdLayer-Setlayer "HATCH")
  26.     )
  27.   )
  28. )
  29. (defun rCmdLayer-SetLayer (name / lay)
  30.   (cond
  31.     ((setq lay (get-item oLay name))
  32.      (if (= :vlax-True (vla-get-lock lay))
  33.        (progn
  34.          (setq $laylock :vlax-True)
  35.          (vla-put-lock lay :vlax-False)
  36.        )
  37.      )
  38.      (if (= :vlax-False
  39.             (vla-get-layeron lay)
  40.             (progn
  41.               (setq $layon :vlax-false)
  42.               (vla-put-layeron lay :vlax-true)
  43.             )
  44.          )
  45.        (if (= :vlax-True (vla-get-Freeze lay))
  46.          (progn
  47.            (setq $layfrz :vlax-true)
  48.            (vla-put-Freeze layobj :vlax-false)
  49.          )
  50.        )
  51.        (vla-put-activelayer aDoc lay)
  52.      )
  53.     )
  54.   )
  55. )
  56. (defun rCmdLayer-Restore (reactor data / data lay)
  57.   (setq cmd (strcase (car data)))        ; get command name
  58. )
  59. ;;;upon completion of command restores *layers* to previous state
  60. (defun al:restore (reactor info / cmd layobj)
  61.   (setq cmd (car info))
  62.   (if
  63.     (and
  64.       *capslock*
  65.       (or
  66.         (wcmatch (strcase cmd)
  67.                  "*LEADER,*QLEADER,*MTEXT,*TEXT,*DDEDIT,*ATTEDIT"
  68.         )
  69.         (and
  70.           (wcmatch
  71.             (strcase cmd)
  72.             "*DIM,*DIMLINEAR,*DIMALIGNED,*DIMORDINATE,*DIMRADIUS,*DIMDIAMETER,*DIMANGULAR,*DIMBASELINE,*DIMCONTINUE,*QDIM,*LEADER,*QLEADER,*MTEXT,*TEXT,*DDEDIT"
  73.           )
  74.           (= (vlax-variant-value (vla-getvariable *adocobj* "dimaso"))
  75.              0
  76.           )
  77.         )
  78.       )
  79.     )
  80.      (dos_capslock)
  81.   )
  82.   (if (< (vlax-variant-value (vla-getvariable *adocobj* "cmdactive"))
  83.          2
  84.       )                                        ;test for transparent commands
  85.     (progn
  86.       (setq layobj (vla-get-ActiveLayer *adocobj*))
  87.                                         ;get ActiveLayer object
  88.       (if offlay                        ; "hidden" layer noted as off (offlay not nil)
  89.         (vlax-put-property
  90.           (vla-item *layers*
  91.                     (if        (wcmatch (strcase (car info)) "*HATCH")
  92.                       "Hidden"
  93.                       "Hatch"
  94.                     )
  95.           )
  96.           "LayerOn"
  97.           1
  98.         )                                ;turn "hidden" layer back on
  99.       )                                        ;end if
  100.       (if
  101.         (and
  102.           clobj                                ; clayer objobject assigned to clobj in al:laystate (clobj not nil)
  103.           (not (equal clobj layobj))        ;if clayer object (clobj set in al:laystate) layer object
  104.         )                                ;end and
  105.          (vla-put-ActiveLayer *adocobj* clobj) ;sets layer current
  106.       )                                        ;end if
  107.       (if layoff                        ; if the layer (layoff set in al:laystate) was noted as off (layoff not nil)
  108.         (vla-put-LayerOn layoff 0)        ;turn it off again
  109.       )                                        ;end if
  110.       (if layfreeze                        ; if layer (layfreeze set in al:laystate) was frozen (layfreeze not nil)
  111.         (vla-put-Freeze layfreeze 1)        ;freeze it again
  112.       )                                        ;end if
  113.       (if laylock                        ; if layer (laylock set in al:laystate) was locked (laylock not nil)
  114.         (vla-put-Lock laylock 1)        ;Lock it again
  115.       )                                        ;end if
  116.       (setq clobj nil
  117.             offlay nil
  118.             layoff nil
  119.             layfreeze nil
  120.             laylock nil
  121.       )                                        ;set global variables to nil
  122.     )                                        ;end progn
  123.   )                                        ;end if
  124. )                                        ;end defun

  125. ;;;======================================================================
  126. ;;;disables commandEnded reactor to avoid errors when using "new" and "open"
  127. ;;;in SDI mode. The error is merely annoying and only appears at the command
  128. ;;;line as "error: no function definition: al:restore" when opening or creating
  129. ;;;a new drawing. The cause of the error is commandEnded reactor present form
  130. ;;;last dwg but LISP has not yet loaded the called function in a new or opened
  131. ;;;dwg. Furthermore, the reactor cannot be removed because it has already been
  132. ;;;activated and is waiting for the command to end. Therefore, the reactor must
  133. ;;;be rendered non-functional by changing its call to the LISP command "LIST".
  134. (defun al:disable (reactor info / tdat)
  135.   (if
  136.     (= (vlax-variant-value (vla-getvariable *adocobj* "sdi")) 1)
  137.                                         ;in SDI mode?
  138.      (vlr-reaction-set
  139.        (car (vlr-object
  140.               '(VLR-Command-reactor
  141.                 nil
  142.                 '((:VLR-commandWillStart . al:autolay)
  143.                   (:VLR-commandEnded . al:restore)
  144.                   (:VLR-commandCancelled . al:restore)
  145.                  )
  146.                )
  147.             )
  148.        )
  149.        :VLR-commandEnded
  150.        'list
  151.      )
  152.   )                                        ;end if
  153. )                                        ;end defun

  154. ;;;======================================================================
  155. ;;;Here's where we set up the reactors to do all this cool stuff
  156. (vlr-set-notification
  157.   (vlr-manager
  158.     '(VLR-DWG-reactor nil '((:VLR-beginClose . al:disable)))
  159.     3
  160.   )
  161.   'active-document-only
  162. )
  163. (vlr-set-notification
  164.   (vlr-manager
  165.     '(VLR-Command-reactor
  166.       nil
  167.       '((:VLR-commandWillStart . al:autolay)
  168.         (:VLR-commandEnded . al:restore)
  169.         (:VLR-commandCancelled . al:restore)
  170.        )
  171.      )
  172.     3
  173.   )
  174.   'active-document-only
  175. )


  176. ;;;======================================================================
  177. ;;;get rid of old reactor if present. The reactor will be present, because in
  178. ;;;SDI mode, it's associated namespace is not destroyed, but has the new drawing
  179. ;;;loaded into it. At the time this file is loaded, this reactor is either not
  180. ;;;present or has been rendered useless (in SDI mode) at the closing of the last
  181. ;;;dwg and is excess loaded code bulk and should be removed. The VLR-MANAGER
  182. ;;;provides an easy means of doing this.
  183. (vlr-manager
  184.   '(VLR-Command-reactor
  185.     nil
  186.     '((:VLR-commandWillStart . al:autolay)
  187.       (:VLR-commandEnded . list)
  188.       (:VLR-commandCancelled . al:restore)
  189.      )
  190.    )
  191.   1
  192. )
  193. ;;;======================================================================
  194. (princ
  195.   "\nAutoLay V2.2 loaded. Type "autolay" or "capslock" to enable/disable."
  196. )
  197. (princ)

  198. ;;;======================================================================
  199. ;|
  200. Set up and installation instructions:
  201. This is kind of an outline of the things you may need to edit to make this program work with your companies drafting standards.

  202. The main body of autolay has the conditions that must be tested for to see if a layer needs to be switched to or created. It is also
  203. where the layer name comes from. (al:laystate "Hatch" cmd) is the first such command (noted as cond 1) in the code to create or
  204. switch to a layer, where "Hatch" is to be the actual name of the layer to be created. The conditions will probably be the most
  205. difficult part to adapt to your companies drafting standards. Lets take a look at cond 6 for example:

  206.         (;cond 5
  207.           (wcmatch cmd "*TEXT");are you creating text?
  208.           (al:laystate "Text" cmd);make, thaw, turn on and make current "Text" layer as needed
  209.         );end cond 5

  210. If the command (cmd) is "*text", then create or switch to a layer named "Text". You can have as many conds and *layers* as you
  211. need. You can also add other parameters such as text style and/or size in different CONDS to put different text styles or sizes
  212. on different *layers*. That would then look more like:

  213.         (;cond 6
  214.           (and
  215.             (wcmatch cmd "*TEXT");are you creating text?
  216.             (wcmatch tst "~SIMPLEX");is the current text style NOT "Simplex"*
  217.             (= tsz (* (getvar "dimscale") 0.0625));is this the current text size?
  218.           );end and
  219.           (al:laystate "Text" cmd);make, thaw, turn on and make current "Text" layer as needed
  220.         );end cond 6

  221. The routine al:ltype is the one that decides what linetype is assigned to a layer (name). Similar is true for al:lweight and al:color.
  222. Edit these to suit your companies drafting standards.

  223. One more thing. If you use a different linetype source file (.lin file format) other than acad.lin or acadiso.lin, you will
  224. have to edit in the name of the linetype file name in the al:mkLay routine.

  225. To disable AutoLay[2.2].lsp, type "autolay" at the commond prompt.

  226. This should be enough to get you going. Pick away, play around with it and learn from it until you get it to do what you want. I
  227. already did the hard part of coding and testing.

  228. Best Regards
  229. Eric Schneider|;
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2004-5-14 09:18:25 | 显示全部楼层
请问斑竹,这如何使用?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

使用道具 举报

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

使用道具 举报

发表于 2004-5-16 21:16:03 | 显示全部楼层
请问如果我不想安装DSX,能单独用上面的程序吗?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

使用道具 举报

已领礼包: 7345个

财富等级: 富甲天下

发表于 2005-10-22 17:48:46 | 显示全部楼层
AutoLay[3.0].zip
分享者(原作者)
Eric Schneider eschneider@spamfree.jensenprecast.com

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-12-26 09:51 , Processed in 0.442324 second(s), 43 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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