明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 14940|回复: 37

自动图层

  [复制链接]
发表于 2011-5-10 20:09:07 | 显示全部楼层 |阅读模式
这个是在明经上找到的自动图层,当标注时就自动转到dim层,非常 好用,只是当我单开一个其它图层时,标注的层dim是被关闭的,结果就看不到所标注的东东,要全开图层才行,请问可不可以加一个功能,让程序在标注时,会自动打开标注层dim(形如下载的地方没找到,只好在这里从新发一个了)
  1. (defun xlr-autolayer ()
  2.   (vl-load-com)
  3.   ;; 图层初始化列表 内容:commands layers color linetype plottable
  4.   (setq *doc (vla-get-activedocument (vlax-get-acad-object)))
  5.   (setq *lays (vla-get-layers *doc))
  6.   (setq  *laylst
  7.    (list (list "DIMANGULAR" "DIM" 3 "continuous" T)
  8.          (list "DIMALIGNED" "DIM" 3 "continuous" T)
  9.          (list "DIMBASELINE" "DIM" 3 "continuous" T)
  10.          (list "DIMCENTER" "DIM" 3 "continuous" T)
  11.          (list "DIMCONTINUE" "DIM" 3 "continuous" T)
  12.          (list "DIMDIAMETER" "DIM" 3 "continuous" T)
  13.          (list "DIMLINEAR" "DIM" 3 "continuous" T)
  14.          (list "DIMORDINATE" "DIM" 3 "continuous" T)
  15.          (list "DIMRADIUS" "DIM" 3 "continuous" T)
  16.          (list "QDIM" "DIM" 3 "continuous" T)
  17.          (list "QLEADER" "DIM" 3 "continuous" T)
  18.          (list "DTEXT" "TXT" 3 "continuous" T)
  19.          (list "MTEXT" "TXT" 3 "continuous" T)
  20.          (list "TEXT" "TXT" 3 "continuous" T)
  21.          ;(list "BHATCH" "填充" 9 "continuous" T)
  22.          ;(list "HATCH" "填充" 9 "continuous" T)
  23.           ;(list "POINT" "点" 4 "continuous" T)
  24.           ;(list "XLINE" "辅助线" 8 "continuous" T)
  25.           ;(list "LINE" "0" NIL "continuous" T)
  26.           ;(list "XREF" "引用" 7 "continuous" T)
  27.           ;(list "pline" "多义线" 2 "center" T)
  28.    )
  29.   )
  30.   (setq OldLayer nil)
  31.   (setq *cmdlst (mapcar 'strcase (mapcar 'car *laylst)))
  32.   (mapcar '(lambda (x) (vlr-command-reactor nil x))
  33.     (list  '((:vlr-commandWillStart . xlr-start))
  34.     '((:vlr-commandEnded . xlr-end))
  35.     '((:vlr-commandCancelled . xlr-cancel))
  36.     )
  37.   )
  38.   (vlr-editor-reactor
  39.     nil
  40.     '((:vlr-commandwillstart . xlr-edit))
  41.   )
  42. )
  43. ;;;----------------------------------------------------------------------------;;;
  44. (defun xlr-edit  (CALL CALLBACK /)
  45.   (foreach N *laylst
  46.     (if  (= (strcase (car CALLBACK)) (strcase (car N)))
  47.           ; 命令反应器返回信息如果与设置的命令相同.
  48.       (progn        ;建立图层

  49.   (apply 'xsetlays (cdr N))
  50.           ;(setvar "CLAYER" (cadr N));设为当前层.
  51.       )
  52.     )
  53.   )
  54. )
  55. ;;;----------------------------------------------------------------------------;;;
  56. (defun xlr-start (calling-reactor xlr-startInfo /)
  57.   (foreach N *laylst
  58.     (if  (= (strcase (car xlr-startInfo)) (strcase (car N)))
  59.           ; 命令反应器返回信息如果与设置的命令相同.
  60.       (progn        ;建立图层

  61.   (apply 'xsetlays (cdr N))
  62.           ;(setvar "CLAYER" (cadr N));设为当前层.
  63.       )
  64.     )
  65.   )
  66. )
  67. ;;;----------------------------------------------------------------------------;;;
  68. (defun xlr-end (calling-reactor xlr-endInfo / cmd)
  69.   (setq cmd (car xlr-endInfo))
  70.   (if (member cmd *cmdlst)
  71.     (if (/= oldlayer nil)
  72.        (progn
  73.            (setvar "CLAYER" OldLayer)
  74.            (setq OldLayer nil)
  75.        )
  76.     )
  77.   )
  78. )
  79. ;;;----------------------------------------------------------------------------;;;
  80. (defun xlr-cancel (calling-reactor xlr-cancelInfo / cmd)
  81.   (setq cmd (car xlr-cancelInfo))
  82.   (if (member cmd *cmdlst)
  83.     (if (/= oldlayer nil)
  84.        (progn
  85.            (setvar "CLAYER" OldLayer)
  86.            (setq OldLayer nil)
  87.        )
  88.     )
  89.   )
  90. )
  91. ;;;----------------------------------------------------------------------------;;;
  92. ;;;----------------------------------------------------------------------------;;;
  93. (defun xsetlays  (LAY-NAM COLOR LTYPE plotk / LAYOBJ LTYPESOBJ)

  94.   (if (tblobjname "layer" LAY-NAM)
  95.     (progn
  96.       (if (/= (strcase (getvar "CLAYER"))
  97.         (strcase LAY-NAM)
  98.     )
  99.   (setq OldLayer (getvar "CLAYER"))
  100.   (progn
  101.     (if (= oldlayer nil)
  102.       (setq OldLayer LAY-NAM)
  103.     )
  104.   )
  105.       )
  106.       (setvar "CLAYER" lay-nam)
  107.     )
  108.     (progn        ;添加图层.
  109.       (vl-catch-all-error-p
  110.   (vl-catch-all-apply 'vla-add (list *lays LAY-NAM))
  111.       )
  112.       (setq LAYOBJ (vla-item *lays LAY-NAM))
  113.       (if (not (tblobjname "ltype" LTYPE)) ;添加线型.
  114.   (progn
  115.     (setq LTYPESOBJ (vla-get-linetypes *doc))
  116.     (vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
  117.           ;>>> 要加强,在多个*.lin寻找
  118.     (vlax-release-object LTYPESOBJ)
  119.   )
  120.       )          ;解冻(如冻结),解锁,设图层为当前,设图层颜色,可打印特性.
  121.       (vla-put-layeron layobj :vlax-true)
  122.       (vla-put-lock layobj :vlax-false)
  123.       (if (= (strcase (getvar "CLAYER")) (COMMAND "layer" "on" "" "")(strcase lay-nam)) ;解冻.
  124.   (vla-put-freeze layobj :vlax-false)
  125.       )
  126.       (vla-put-color layobj color)
  127.       (vla-put-linetype layobj LTYPE)
  128.       (vla-put-plottable
  129.   layobj
  130.   (if plotk
  131.     :vlax-true
  132.     :vlax-false
  133.   )
  134.       )
  135.     )
  136.   )
  137. )
  138. (xlr-autolayer)        ;加载启动!

发表于 2016-5-15 20:34:51 | 显示全部楼层
SunSpring 发表于 2011-5-11 20:37
试下这个如何.

把124行的(vla-put-color layobj color)放到121行前面去,不然设置的图层颜色不起作用
回复 支持 1 反对 0

使用道具 举报

发表于 2023-8-23 20:55:37 | 显示全部楼层
ㄘ丶转裑ㄧ灬 发表于 2016-5-15 20:34
把124行的(vla-put-color layobj color)放到121行前面去,不然设置的图层颜色不起作用

大神呀,我说怎么颜色都是白的
发表于 2018-11-6 21:34:45 | 显示全部楼层
大家看下面的帖子
关于标注自动分层
http://bbs.mjtd.com/forum.php?mo ... hlight=%B1%EA%D7%A2
 楼主| 发表于 2011-5-10 20:09:40 | 显示全部楼层
期待高手来解决
发表于 2011-5-10 21:02:03 | 显示全部楼层
自动图层,扬起~
发表于 2011-5-10 22:51:40 | 显示全部楼层
我知道需要命令才可实现标注自动到标注层
 楼主| 发表于 2011-5-11 17:28:42 | 显示全部楼层
我把它顶起来
发表于 2011-5-11 20:37:51 | 显示全部楼层
本帖最后由 SunSpring 于 2011-5-11 20:38 编辑

  1. (defun xlr-autolayer ()
  2.   ;; 图层初始化列表 内容:commands layers color linetype plottable
  3.   (setq *doc (vla-get-activedocument (vlax-get-acad-object)))
  4.   (setq *lays (vla-get-layers *doc))
  5.   (setq  *laylst
  6.     (list (list "DIMANGULAR" "DIM" 3 "continuous" T)
  7.           (list "DIMALIGNED" "DIM" 3 "continuous" T)
  8.           (list "DIMBASELINE" "DIM" 3 "continuous" T)
  9.           (list "DIMCENTER" "DIM" 3 "continuous" T)
  10.           (list "DIMCONTINUE" "DIM" 3 "continuous" T)
  11.           (list "DIMDIAMETER" "DIM" 3 "continuous" T)
  12.           (list "DIMLINEAR" "DIM" 3 "continuous" T)
  13.           (list "DIMORDINATE" "DIM" 3 "continuous" T)
  14.           (list "DIMRADIUS" "DIM" 3 "continuous" T)
  15.           (list "QDIM" "DIM" 3 "continuous" T)
  16.           (list "QLEADER" "DIM" 3 "continuous" T)
  17.           (list "DTEXT" "TXT" 3 "continuous" T)
  18.           (list "MTEXT" "TXT" 3 "continuous" T)
  19.           (list "TEXT" "TXT" 3 "continuous" T)
  20.          ;(list "BHATCH" "填充" 9 "continuous" T)
  21.          ;(list "HATCH" "填充" 9 "continuous" T)
  22.          ;(list "POINT" "点" 4 "continuous" T)
  23.          ;(list "XLINE" "辅助线" 8 "continuous" T)
  24.          ;(list "LINE" "0" NIL "continuous" T)
  25.          ;(list "XREF" "引用" 7 "continuous" T)
  26.          ;(list "pline" "多义线" 2 "center" T)
  27.     )
  28.   )
  29.   (setq OldLayer nil)
  30.   (setq *cmdlst (mapcar 'strcase (mapcar 'car *laylst)))
  31.   (mapcar '(lambda (x) (vlr-command-reactor nil x))
  32.     (list  '((:vlr-commandWillStart . xlr-start))
  33.     '((:vlr-commandEnded . xlr-end))
  34.     '((:vlr-commandCancelled . xlr-cancel))
  35.     )
  36.   )
  37.   (vlr-editor-reactor nil '((:vlr-commandwillstart . xlr-edit)))
  38. )
  39. ;;;----------------------------------------------------------------------------;;;
  40. (defun xlr-edit  (call callback / n)
  41.   (foreach n *laylst
  42.     (if  (= (strcase (car callback)) (strcase (car n)))
  43.       (apply 'xsetlays (cdr n))
  44.     )
  45.   )
  46. )
  47. ;;;----------------------------------------------------------------------------;;;
  48. (defun xlr-start (calling-reactor xlr-startinfo / n)
  49.   (foreach n *laylst
  50.     (if (= (strcase (car xlr-startinfo)) (strcase (car n)))  
  51.       (apply 'xsetlays (cdr n))
  52.     )
  53.   )
  54. )
  55. ;;;----------------------------------------------------------------------------;;;
  56. (defun xlr-end (calling-reactor xlr-endinfo / cmd)
  57.   (setq cmd (car xlr-endinfo))
  58.   (if (member cmd *cmdlst)
  59.     (if (/= oldlayer nil)
  60.       (progn
  61.         (setvar "clayer" oldlayer)
  62.         (setq oldlayer nil)
  63.       )
  64.     )
  65.   )
  66. )
  67. ;;;----------------------------------------------------------------------------;;;
  68. (defun xlr-cancel (calling-reactor xlr-cancelinfo / cmd)
  69.   (setq cmd (car xlr-cancelinfo))
  70.   (if (member cmd *cmdlst)
  71.     (if (/= oldlayer nil)
  72.       (progn
  73.         (setvar "clayer" oldlayer)
  74.         (setq oldlayer nil)
  75.       )
  76.     )
  77.   )
  78. )
  79. ;;;----------------------------------------------------------------------------;;;
  80. ;;;----------------------------------------------------------------------------;;;
  81. (defun xsetlays  (lay-nam color ltype plotk / layobj ltypesobj)
  82.   (defun layeron (layername / layerdata)
  83.     (setq layerdata (entget (tblobjname "LAYER" layername)))
  84.     (if (< (cdr (assoc 62 layerdata)) 0)
  85.       (progn
  86.         (setq layerdata (subst
  87.                           (cons 62 (- 0 (cdr (assoc 62 layerdata))))
  88.                           (assoc 62 layerdata)
  89.                           layerdata
  90.                         )
  91.         )
  92.         (entmod layerdata)
  93.       )
  94.     )
  95.   )
  96.   (if (tblobjname "layer" lay-nam)
  97.     (progn
  98.       (if (/= (strcase (getvar "clayer")) (strcase lay-nam))
  99.         (setq oldlayer (getvar "clayer"))
  100.         (progn
  101.           (if (= oldlayer nil)
  102.             (setq oldlayer lay-nam)
  103.           )
  104.         )
  105.       )
  106.       (layeron lay-nam)
  107.       (setvar "clayer" lay-nam)
  108.     )
  109.     (progn
  110.       (vl-catch-all-error-p (vl-catch-all-apply 'vla-add (list *lays lay-nam)))
  111.       (setq layobj (vla-item *lays lay-nam))
  112.       (if (not (tblobjname "ltype" ltype)) ;添加线型.
  113.         (progn
  114.           (setq ltypesobj (vla-get-linetypes *doc))
  115.           (vla-load ltypesobj ltype (findfile "acad.lin"))  ;>>> 要加强,在多个*.lin寻找
  116.           (vlax-release-object ltypesobj)
  117.         )
  118.       )
  119.       (vla-put-layeron layobj :vlax-true)
  120.       (vla-put-lock layobj :vlax-false)
  121.       (if (= (strcase (getvar "clayer")) (command "layer" "on" "" "")(strcase lay-nam)) ;解冻.
  122.         (vla-put-freeze layobj :vlax-false)
  123.       )
  124.       (vla-put-color layobj color)
  125.       (vla-put-linetype layobj LTYPE)
  126.       (vla-put-plottable layobj (if plotk :vlax-true :vlax-false))
  127.     )
  128.   )
  129. )
  130. (xlr-autolayer)        ;加载启动!


试下这个如何.

点评

命令: ; 错误: no function definition: VLAX-GET-ACAD-OBJECT 可以看下 怎么回事呀 我用的是09版  发表于 2012-10-17 21:19
(list "HATCH" "填充" 9 "continuous" T) 朋友,能给菜鸟解释一下这行程序中各关键词的意义吗?比如 9 ---- continuous---- T----  发表于 2012-8-26 17:09
 楼主| 发表于 2011-5-11 23:40:46 | 显示全部楼层
回复 SunSpring 的帖子

谢谢楼主,这个非常好用
发表于 2011-5-17 12:32:04 | 显示全部楼层
         是龙版主的Autolayer差不多的吧
发表于 2011-5-21 07:58:27 | 显示全部楼层
SunSpring 发表于 2011-5-11 20:37
试下这个如何.

我写了几句插入时间的程序,用了你的自动图层后,系统就崩溃了。
;插入时间
(defun hh-time( / pt0 date0 scal pt1)
(vl-cmdf "ucs" "")
(setq scal (getvar "dimscale"))
(setq pt0 (getpoint "\n点取时间插入右下角:"))
(setq pt0 (polar pt0 PI (* 1.5 scal)))
(setq pt0 (polar pt0 (/ pi 2) (* 1.25 scal)))
(setq date0 (menucmd "M=$(edtime,$(getvar,date),YYYY.MO.DD)"))
(setq pt1 (polar pt0 PI (* 12 scal)))
(vl-cmdf "text" "j" "f" pt1 pt0 (* 3.5 scal) date0)
(princ)
)
发表于 2011-5-23 01:46:06 | 显示全部楼层
本帖最后由 啵浪鼓 于 2011-5-23 02:53 编辑

挺好的反应器
解冻/解锁
(if (/= (cdr (assoc 70 layerdata)) 0)
      (progn
        (setq layerdata (subst
                          (cons 70 0)
                          (assoc 70 layerdata)
                          layerdata
                        )
        )
        (entmod layerdata)
      )
    )
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-17 03:41 , Processed in 0.169717 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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