明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 21033|回复: 59

自动切换图层 VLISP测试版(Autolayer.vlx)

  [复制链接]
发表于 2004-4-10 16:03:00 | 显示全部楼层 |阅读模式

自动切换图层 VLISP测试版(Autolayer.vlx)
关键主程序(MEFLYING提供)请参考
[我也感觉不出用VL有什么优势,程序用entmake建图层,setvar改作用图层,看看是否真有不能用的原因]


在绘图中,有些命令我们会使用指定的图层来存放,以便于图形的组
织,如标注对像应该放在标注层上,而填充图案放到填充图案相关的
图层中。但是如果在绘图时手动切换图层,则很麻烦。有没有程序会
自动辨别不同的命令来切换不同的图层,让自己不必去关心当前的图
层状态呢?

这个程序就是用来实现这个功能的。标注尺寸时,如果指定的尺寸层
已经存在,就转到尺寸层上,如果还没有尺寸层,就会自动建一个。
其它命令,只要不是透明命令/缩写命令,都可以到指定层上去,至于
具体是什么层,请看配置文件 Autolayer.ini。


配置文件 Autolayer.ini 格式:
命令 图层名称 图层颜色 图层线型
"DIMLINEAR" "DIM" 4 "CONTINUOUS"


你可以随意添加命令和层的对应关系。但命令不能是 AutoLISP 的函
数产生的命令。 Autolayer.ini 可直接用记事本打开编辑。


程序加载方法:
将 Autolayer.lsp、Autolayer.ini
复制到 R200X 的搜寻目录下(LOAD "Autolayer")即可。


多重配置通过在命令行输入(LAYER_GROUP <组名>)来实现,
如组名="GROUP1"则采用[LAYER_GROUP1]内的配置,如果找不到对应的
组名,则保留原配置。


为了使用方便,您可以在ACAD里加上一些按钮,按钮执行一个命令,
如 (LAYER_GROUP NIL)或(LAYER_GROUP "GROUP1")………与配置文件对应。
具体方法请参考有关书籍。


指令:TOGGLE_AUTOLAYER ;可切换Autolayer

dispbbs.asp?boardID=3&ID=18953&star=3&page=1

本帖子中包含更多资源

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

x
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2023-10-26 19:06:32 | 显示全部楼层
如果图层与标准图层颜色不一致怎么改?
发表于 2022-6-15 13:04:30 | 显示全部楼层
下来试下,一直在找一款好用的图层工具!
发表于 2022-6-15 14:47:39 | 显示全部楼层
这就有点厉害了,疯狂回帖赚积分
发表于 2004-4-10 17:27:00 | 显示全部楼层
[建议]是否可以存一组数据到图形中,这样,如果单个文档有特殊需求,每次打开它,不需要新建一个组或进行切换,而是直接读取图形中的数据,如果读取失败,再读取Autolayer.ini文件中的数据
发表于 2004-4-10 17:50:00 | 显示全部楼层
DSX 工具集中的吧:)
发表于 2004-4-10 19:11:00 | 显示全部楼层
。但命令不能是 AutoLISP 的函
数产生的命令。 有什么办法解决么?大伙讨论下。等考完试我再杀回马枪 :)
发表于 2004-4-10 19:30:00 | 显示全部楼层
切换层是很方便,但是除了标注尺寸外大部分都是线条,我觉得实际真正有意义的因该是把层颜色线型捆绑在一起,比如如果我要划一根虚线那么我会用xuline命令(举例),这样这根线就会画到我希望的层上包括线型颜色都是我所希望的,当然也可以定义不同的快捷键来实现不同的线型层颜色的线.....
发表于 2004-4-10 20:01:00 | 显示全部楼层
楼上,你说的跟跟我们讨论的问题是不一样的,这里讨论的问题说在平常使用的系统命令的时候自动切换到需要的图层问题,而楼上的用了xuline,就表示用自定义命令,如果是自定义命令,就没有什么问题了,你想定义成什么样子就定义成什么样子...


TO无痕:再加一个:VLR-Lisp-Reactor        反应器应该行吧(未试,你做个上来喽)


TO EA:你可以看看楼主给的链接(再往前一点看),是网友提出了这个要求,我写的一个实现功能的基本程序,至于DSX我确实没听说过(因为我自己一般不用开发的东西,所以都不会到处找工具来用的),其实实现并不困难,问题是要想得到,这个问题也是会员"晓雨"提出来的,所以"版权"问题,你应该去跟她讨论吧...
发表于 2004-4-10 20:13:00 | 显示全部楼层
我只是觉得把系统命令和层联系在一起到底有多大的实用性。。。
发表于 2004-4-10 20:58:00 | 显示全部楼层
meflying发表于2004-4-10 20:01:00楼上,你说的跟跟我们讨论的问题是不一样的,这里讨论的问题说在平常使用的系统命令的时候自动切换到需要的图层问题,而楼上的用了xuline,就表示用自定义命令,如果是...
我和版主相反,找的多,既然版主说了,我也贴一个
  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|;
http://www.xdcad.net/forum/file_upload/56074_a.gif
发表于 2004-4-10 20:59:00 | 显示全部楼层
你用用不就知道了?


-----你想标注的时候(点击或输入标注命令,同平常使用一样,不需要再做别的任何事情),系统自动切换到标注层,你想填充,系统自动切换到填充层,省去了你自己切换图层的工作,会没有实用性?
发表于 2004-4-11 19:20:00 | 显示全部楼层
版权所有,翻录必究,那个ljcgq啊,我不是故意吓唬你,这个问题比较的严重,啊!你可要知难而退,你不想想,我跟版主是什么交情,啊!那是........,唉呀,跟你说了也不明白,就这样吧,你好好反省反省?BY。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-9-28 23:28 , Processed in 0.181798 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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