龙龙仔 发表于 2004-4-10 16:03:00

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

<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">自动切换图层 VLISP测试版(Autolayer.vlx)<BR>关键主程序(MEFLYING提供)请参考<BR>[我也感觉不出用VL有什么优势,程序用entmake建图层,setvar改作用图层,看看是否真有不能用的原因]



<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><BR>



<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">


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



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



<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><BR>配置文件 Autolayer.ini 格式:<BR>                               命令                                                                       图层名称                       图层颜色                               图层线型               <BR>        "DIMLINEAR"                                       "DIM"                                                               4                                       "CONTINUOUS"



<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><BR>你可以随意添加命令和层的对应关系。但命令不能是 AutoLISP 的函<BR>数产生的命令。 Autolayer.ini 可直接用记事本打开编辑。



<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><BR>程序加载方法:<BR>将 Autolayer.lsp、Autolayer.ini <BR>复制到 R200X 的搜寻目录下(LOAD "Autolayer")即可。



<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><BR>多重配置通过在命令行输入(LAYER_GROUP &lt;组名&gt;)来实现,<BR>如组名="GROUP1"则采用内的配置,如果找不到对应的<BR>组名,则保留原配置。



<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><BR>为了使用方便,您可以在ACAD里加上一些按钮,按钮执行一个命令,<BR>如 (LAYER_GROUP NIL)或(LAYER_GROUP "GROUP1")………与配置文件对应。<BR>具体方法请参考有关书籍。



<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><BR>指令:TOGGLE_AUTOLAYER       ;可切换Autolayer






<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">       







<FONT face="Times New Roman">
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun"><A href="dispbbs.asp?boardID=3&amp;ID=18953&amp;star=3&amp;page=1" target="_blank" >dispbbs.asp?boardID=3&amp;ID=18953&amp;star=3&amp;page=1</A><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

</FONT></SPAN>

ferious 发表于 2023-10-26 19:06:32

如果图层与标准图层颜色不一致怎么改?

青冥 发表于 2022-6-15 13:04:30

下来试下,一直在找一款好用的图层工具!:handshake

smile0421 发表于 2022-6-15 14:47:39

这就有点厉害了,疯狂回帖赚积分

meflying 发表于 2004-4-10 17:27:00

[建议]是否可以存一组数据到图形中,这样,如果单个文档有特殊需求,每次打开它,不需要新建一个组或进行切换,而是直接读取图形中的数据,如果读取失败,再读取Autolayer.ini文件中的数据

Ea 发表于 2004-4-10 17:50:00

DSX 工具集中的吧:)

无痕 发表于 2004-4-10 19:11:00

。但命令不能是 AutoLISP 的函<BR>数产生的命令。


有什么办法解决么?大伙讨论下。等考完试我再杀回马枪 :)

ljcgq 发表于 2004-4-10 19:30:00

切换层是很方便,但是除了标注尺寸外大部分都是线条,我觉得实际真正有意义的因该是把层颜色线型捆绑在一起,比如如果我要划一根虚线那么我会用xuline命令(举例),这样这根线就会画到我希望的层上包括线型颜色都是我所希望的,当然也可以定义不同的快捷键来实现不同的线型层颜色的线.....

meflying 发表于 2004-4-10 20:01:00

楼上,你说的跟跟我们讨论的问题是不一样的,这里讨论的问题说在平常使用的系统命令的时候自动切换到需要的图层问题,而楼上的用了xuline,就表示用自定义命令,如果是自定义命令,就没有什么问题了,你想定义成什么样子就定义成什么样子...


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


TO EA:你可以看看楼主给的链接(再往前一点看),是网友提出了这个要求,我写的一个实现功能的基本程序,至于DSX我确实没听说过(因为我自己一般不用开发的东西,所以都不会到处找工具来用的),其实实现并不困难,问题是要想得到,这个问题也是会员"晓雨"提出来的,所以"版权"问题,你应该去跟她讨论吧...

ljcgq 发表于 2004-4-10 20:13:00

我只是觉得把系统命令和层联系在一起到底有多大的实用性。。。

Ea 发表于 2004-4-10 20:58:00

meflying发表于2004-4-10 20:01:00static/image/common/back.gif楼上,你说的跟跟我们讨论的问题是不一样的,这里讨论的问题说在平常使用的系统命令的时候自动切换到需要的图层问题,而楼上的用了xuline,就表示用自定义命令,如果是...我和版主相反,找的多,既然版主说了,我也贴一个
;;;*********************************************************
;;;*********************************************************
(vl-load-com)
(defun get-item (collection item / result)
   (cond
       ((not
             (vl-catch-all-error-p
(setq result
(vl-catch-all-apply 'vla-item (list collection item))
)
             )
         )
         result
       )
   )
)
(setq oAcad (vlax-get-acad-object) ; acadapplication object
         oDoc   (vla-get-activedocument oAcad) ; activedocument object
         oLay   (vla-get-layers oDoc) ; layers collection of activedocument
)
(defun rCmdLayer (reactor data / cmd)
   (setq cmd (strcase (car data))) ; get command name
   (cond
       ((wcmatch cmd "*HATCH") ;is the command "*hatch"?
         (rCmdLayer-Setlayer "HATCH")
       )
   )
)
(defun rCmdLayer-SetLayer (name / lay)
   (cond
       ((setq lay (get-item oLay name))
         (if (= :vlax-True (vla-get-lock lay))
             (progn
(setq $laylock :vlax-True)
(vla-put-lock lay :vlax-False)
             )
         )
         (if (= :vlax-False
       (vla-get-layeron lay)
       (progn
         (setq $layon :vlax-false)
         (vla-put-layeron lay :vlax-true)
       )
)
             (if (= :vlax-True (vla-get-Freeze lay))
(progn
   (setq $layfrz :vlax-true)
   (vla-put-Freeze layobj :vlax-false)
)
             )
             (vla-put-activelayer aDoc lay)
         )
       )
   )
)
(defun rCmdLayer-Restore (reactor data / data lay)
   (setq cmd (strcase (car data))) ; get command name
)
;;;upon completion of command restores *layers* to previous state
(defun al:restore (reactor info / cmd layobj)
   (setq cmd (car info))
   (if
       (and
         *capslock*
         (or
(wcmatch (strcase cmd)
"*LEADER,*QLEADER,*MTEXT,*TEXT,*DDEDIT,*ATTEDIT"
)
(and
   (wcmatch
       (strcase cmd)
       "*DIM,*DIMLINEAR,*DIMALIGNED,*DIMORDINATE,*DIMRADIUS,*DIMDIAMETER,*DIMANGULAR,*DIMBASELINE,*DIMCONTINUE,*QDIM,*LEADER,*QLEADER,*MTEXT,*TEXT,*DDEDIT"
   )
   (= (vlax-variant-value (vla-getvariable *adocobj* "dimaso"))
         0
   )
)
         )
       )
         (dos_capslock)
   )
   (if (< (vlax-variant-value (vla-getvariable *adocobj* "cmdactive"))
2
         ) ;test for transparent commands
       (progn
         (setq layobj (vla-get-ActiveLayer *adocobj*))
;get ActiveLayer object
         (if offlay ; "hidden" layer noted as off (offlay not nil)
(vlax-put-property
   (vla-item *layers*
       (if (wcmatch (strcase (car info)) "*HATCH")
         "Hidden"
         "Hatch"
       )
   )
   "LayerOn"
   1
) ;turn "hidden" layer back on
         ) ;end if
         (if
(and
   clobj ; clayer objobject assigned to clobj in al:laystate (clobj not nil)
   (not (equal clobj layobj)) ;if clayer object (clobj set in al:laystate) layer object
) ;end and
(vla-put-ActiveLayer *adocobj* clobj) ;sets layer current
         ) ;end if
         (if layoff ; if the layer (layoff set in al:laystate) was noted as off (layoff not nil)
(vla-put-LayerOn layoff 0) ;turn it off again
         ) ;end if
         (if layfreeze ; if layer (layfreeze set in al:laystate) was frozen (layfreeze not nil)
(vla-put-Freeze layfreeze 1) ;freeze it again
         ) ;end if
         (if laylock ; if layer (laylock set in al:laystate) was locked (laylock not nil)
(vla-put-Lock laylock 1) ;Lock it again
         ) ;end if
         (setq clobj nil
       offlay nil
       layoff nil
       layfreeze nil
       laylock nil
         ) ;set global variables to nil
       ) ;end progn
   ) ;end if
) ;end defun

;;;======================================================================
;;;disables commandEnded reactor to avoid errors when using "new" and "open"
;;;in SDI mode. The error is merely annoying and only appears at the command
;;;line as "error: no function definition: al:restore" when opening or creating
;;;a new drawing. The cause of the error is commandEnded reactor present form
;;;last dwg but LISP has not yet loaded the called function in a new or opened
;;;dwg. Furthermore, the reactor cannot be removed because it has already been
;;;activated and is waiting for the command to end. Therefore, the reactor must
;;;be rendered non-functional by changing its call to the LISP command "LIST".
(defun al:disable (reactor info / tdat)
   (if
       (= (vlax-variant-value (vla-getvariable *adocobj* "sdi")) 1)
;in SDI mode?
         (vlr-reaction-set
             (car (vlr-object
         '(VLR-Command-reactor
nil
'((:VLR-commandWillStart . al:autolay)
   (:VLR-commandEnded . al:restore)
   (:VLR-commandCancelled . al:restore)
)
             )
       )
             )
             :VLR-commandEnded
             'list
         )
   ) ;end if
) ;end defun

;;;======================================================================
;;;Here's where we set up the reactors to do all this cool stuff
(vlr-set-notification
   (vlr-manager
       '(VLR-DWG-reactor nil '((:VLR-beginClose . al:disable)))
       3
   )
   'active-document-only
)
(vlr-set-notification
   (vlr-manager
       '(VLR-Command-reactor
         nil
         '((:VLR-commandWillStart . al:autolay)
(:VLR-commandEnded . al:restore)
(:VLR-commandCancelled . al:restore)
             )
         )
       3
   )
   'active-document-only
)


;;;======================================================================
;;;get rid of old reactor if present. The reactor will be present, because in
;;;SDI mode, it's associated namespace is not destroyed, but has the new drawing
;;;loaded into it. At the time this file is loaded, this reactor is either not
;;;present or has been rendered useless (in SDI mode) at the closing of the last
;;;dwg and is excess loaded code bulk and should be removed. The VLR-MANAGER
;;;provides an easy means of doing this.
(vlr-manager
   '(VLR-Command-reactor
       nil
       '((:VLR-commandWillStart . al:autolay)
         (:VLR-commandEnded . list)
         (:VLR-commandCancelled . al:restore)
         )
   )
   1
)
;;;======================================================================
(princ
   "\nAutoLay V2.2 loaded. Type \"autolay\" or \"capslock\" to enable/disable."
)
(princ)

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

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
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
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
difficult part to adapt to your companies drafting standards. Lets take a look at cond 6 for example:

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

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
need. You can also add other parameters such as text style and/or size in different CONDS to put different text styles or sizes
on different *layers*. That would then look more like:

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

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.
Edit these to suit your companies drafting standards.

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

To disable AutoLay.lsp, type "autolay" at the commond prompt.

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
already did the hard part of coding and testing.

Best Regards
Eric Schneider|;http://www.xdcad.net/forum/file_upload/56074_a.gif

meflying 发表于 2004-4-10 20:59:00

你用用不就知道了?


-----你想标注的时候(点击或输入标注命令,同平常使用一样,不需要再做别的任何事情),系统自动切换到标注层,你想填充,系统自动切换到填充层,省去了你自己切换图层的工作,会没有实用性?

晓雨 发表于 2004-4-11 19:20:00

版权所有,翻录必究,那个<A name=11239><FONT color=#000066><B>ljcgq</B></FONT></A>啊,我不是故意吓唬你,这个问题比较的严重,啊!你可要知难而退,你不想想,我跟版主是什么交情,啊!那是........,唉呀,跟你说了也不明白,就这样吧,你好好反省反省?BY。
页: [1] 2 3 4 5 6
查看完整版本: 自动切换图层 VLISP测试版(Autolayer.vlx)