明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1794|回复: 10

[提问] 【求助】论坛图层合并V2.3源码

[复制链接]
发表于 2019-5-31 22:00 | 显示全部楼层 |阅读模式
  1. ;http://bbs.xdcad.net/thread-669308-1-1.html
  2. ;by eachy ;flowerson 修改
  3. (vl-load-com)
  4. (if (>= (atof (getvar "acadver")) 16.0)
  5.   (vl-arx-import "acapp.arx")
  6.   (vl-arx-import "acadapp.arx")
  7. )
  8. ;|
  9. 全局变量
  10.     nlyr  新图层
  11.     llyr  转换列表
  12.     name  图层列表
  13.     fillc 新图层颜色
  14.     tf    保留颜色     "1" 保留 "0" 不保留
  15.     tf1   保留线形     "1" 保留 "0" 不保留
  16.     ltf   忽略块内0层  "1" 忽略 "0" 修改
  17. |;
  18. (defun c:Lyrt (/ ea:string_parse      ea:string_unparse
  19.    ea:pross      ea:get-utime  RGBtoOLE_color
  20.    OLEtoRGB_color       RGBtoACI
  21.    ea:getcecolor ea:chglyrcolor
  22.    ea:translyr   ea:chgcolor   ea:fillcolor
  23.    ea:pre        ea:table      getsslyr
  24.    myerr        mknewlyr      ea:clearcset
  25.    thisdrawing   blocks      layers
  26.    name        nullss      olderr
  27.    ltf        nlyr      llyr
  28.    fillc        tf      tf1
  29.    _$ver        _ealyrtr_id   what_next
  30.    oAcad        x  tmp bn
  31.   )
  32.   ;|(if (or (> (atoi (rtos (getvar "cdate") 2 0)) 20041231)
  33.    (< (atoi (rtos (getvar "cdate") 2 0)) 20040906)
  34.       )
  35.     (vla-eval
  36.       (vlax-get-acad-object)
  37.       (strcat
  38. "MsgBox "\nAuthor: Eachy\n\nhttp:\\\\www.xdcad.net""
  39. ", "
  40. "vbExclamation+vbSystemModal"
  41. ", "
  42. ""Layer Merge V2.3 ""
  43.        )
  44.     ) ;_ end eval
  45.   ) ;_ end if|;
  46.   (defun ea:table (s / d r)
  47.     (while (setq d (tblnext s (null d)))
  48.       (setq r (cons (cdr (assoc 2 d)) r))
  49.     )
  50.     (acad_strlsort (reverse r))
  51.   )
  52.   (defun ea:string_parse (str delimiter / post strlst)
  53.     (if str
  54.       (progn
  55. (setq strlst '())
  56. (while (vl-string-search delimiter str)
  57.    (setq post (vl-string-search delimiter str))
  58.    (setq strlst (append strlst (list (substr str 1 post))))
  59.    (setq str (substr str (+ post 2)))
  60. )
  61. (vl-remove "" (append strlst (list str)))
  62.       )
  63.     ) ;_ end if
  64.   ) ;_ end defun ea:string_pase
  65.   (defun ea:string_unparse (lst delimiter / return)
  66.     (setq return "")
  67.     (foreach str lst
  68.       (setq return (strcat return delimiter str))
  69.     )
  70.     (substr return 2)
  71.   )
  72.   ;;一个在状态条显示处理进度的函数
  73.   ;; k 数 l 长度
  74.   (defun Ea:pross (k l)
  75.     (grtext -2
  76.      (strcat "已完成"
  77.       (rtos (/ (* 100.0 k) l)
  78.      2
  79.      0
  80.       )
  81.       "%...."
  82.      )
  83.     )
  84.   )
  85.   (defun ea:get-utime ()
  86.     (* 86400 (getvar "tdusrtimer"))
  87.   )
  88.   ;; Convert a list of RGB to TrueColor
  89.   ;; (RGBtoOLE_color '(118 118 118))
  90.   (defun RGBtoOLE_color (RGB-codes / r g b)
  91.     (setq r (lsh (car RGB-codes) 16))
  92.     (setq g (lsh (cadr RGB-codes) 8))
  93.     (setq b (caddr RGB-codes))
  94.     (+ (+ r g) b)
  95.   )
  96.   ;;Truecolor -> rgb
  97.   (defun OLEtoRGB_color (OLE_color / r g b)
  98.     (setq r (lsh OLE_color -16))
  99.     (setq g (lsh (lsh OLE_color 16) -24))
  100.     (setq b (lsh (lsh OLE_color 24) -24))
  101.     (strcat "RGB:"
  102.      (vl-princ-to-string r)
  103.      ","
  104.      (vl-princ-to-string g)
  105.      ","
  106.      (vl-princ-to-string b) ;(list r g b))
  107.     )
  108.   )
  109.   ;;
  110.   (defun RGBtoACI (RGB-codes / colorobj)
  111.     (setq
  112.       ColorObj (vla-GetInterfaceObject oAcad "AutoCAD.AcCmColor.16")
  113.     )
  114.     (vlax-invoke
  115.       ColorObj
  116.       'setRGB
  117.       (car RGB-codes)
  118.       (cadr RGB-codes)
  119.       (caddr RGB-codes)
  120.     )
  121.     (vlax-get-property ColorObj 'ColorIndex)
  122.   )
  123.   (defun ea:Clearcset (/ cset)
  124.     (if (not (vl-catch-all-error-p
  125.         (setq cset
  126.         (vl-catch-all-apply
  127.    'vla-item
  128.    (list
  129.      (vla-get-selectionsets thisdrawing)
  130.      "CURRENT"
  131.    )
  132.         )
  133.         )
  134.       )
  135. )
  136.       (vla-delete cset)
  137.     )
  138.     (princ)
  139.   )
  140.   ;;**************************************************************************
  141.   ;;转换主程序
  142.   (defun ea:translyr (/ ea:chg_layer_color_ltyp_0     ea:chgattblk
  143.    ea:chg_ssget_blockdef
  144.    ea:chg_not_ssget_blockdef     llyrc
  145.    lt        t0       nl
  146.    filter        cset       l
  147.    n        s       sl
  148.    t1        blst       ll
  149.    lt        x       nllyr
  150.    0colorobj      0_in       e0 all_0 nn tmp
  151.          )
  152.     ;;修改实体  mark 0 层实体块内/非块内标志, 如果 0 不在llyr中,块内 0 层仅涉及颜色
  153.     (defun ea:chg_layer_color_ltyp_0 (obj mark / alyr cl colobj olt)
  154.       ;;处理块内 object 及属性
  155.       (if (/= (cdr (assoc
  156.        0
  157.        (entget
  158.          (vlax-vla-object->ename
  159.     obj
  160.          )
  161.        )
  162.      )
  163.        )
  164.        "ACAD_PROXY_ENTITY"
  165.    ) ;_ 排除代理实体
  166. (progn
  167.    (setq alyr (vla-get-layer obj))
  168.    ;;保存实体原始特性
  169.    (if _$ver
  170.      (progn
  171.        (setq colobj (vla-get-truecolor obj)
  172.       cl    (vla-get-colorindex colobj )
  173.        )
  174.        (if (= cl 256) ;_ bylayer
  175.   (setq colobj (cdr (assoc alyr llyrc)))
  176.        )
  177.      ) ;_ 2004/2005 特性
  178.      (if (= (setq cl (vla-get-color obj )) 256)
  179.        (setq cl (cdr (assoc alyr llyrc)))
  180.      )
  181.    )
  182.    ;;修改图层
  183.    (if (and (/= alyr nlyr)
  184.      (not (and mark (= alyr "0") (= ltf "1")))
  185.        ) ;_ 只有忽略块内 0 时不改图层
  186.      (vla-put-layer obj  nlyr)
  187.    ) ;_ end if
  188.    ;;恢复颜色
  189.    (if (= tf "1") ;_ 保留
  190.      (cond
  191.        ((and mark
  192.       (= alyr "0") ;_ 0 层实体
  193.       (= cl 256) ;_ bylayer
  194.         )
  195.         (if _$ver
  196.    (progn
  197.      (vla-put-colorindex colobj  acByblock) ;_ 只有块内实体才需要改
  198.      (vla-put-truecolor obj ' colobj)
  199.    )
  200.    (vla-put-color obj  0)
  201.         ) ;_ byblock
  202.        )
  203.        ((and (/= alyr nlyr) (= cl 256)) ;_ bylayer 非0层实体
  204.         (if _$ver
  205.    ;;取图层颜色
  206.    (vla-put-truecolor obj  colobj)
  207.    (vla-put-color obj cl)
  208.         ) ;_ end if
  209.        )
  210.        (t)
  211.      ) ;_ end cond
  212.      ;;不保留颜色
  213.      (if (and _$ver
  214.        (/= cl 256)
  215.   )
  216.        (progn
  217.   (vla-put-colorindex colobj 256);_ bylayer
  218.   (vla-put-truecolor obj  colobj)
  219.        )
  220.        (vla-put-color obj  256)
  221.      )
  222.    ) ;_end if
  223.    ;;不保留线形
  224.    (if (= tf1 "1")
  225.      (if (and (= (setq olt (vla-get-linetype obj ))
  226.    "BYLAYER"
  227.        )
  228.        (/= olt "BYBLOCK")
  229.        (vlax-property-available-p obj 'linetype t)
  230.   )
  231.        (vlax-put-property obj 'linetype (cdr (assoc alyr lt)))
  232.      )
  233.      (if (and (/= (vla-get-linetype obj ) "BYLAYER")
  234.        (vlax-property-available-p obj 'linetype t)
  235.   )
  236.        (vla-put-linetype obj ' "BYLAYER")
  237.      )
  238.    ) ;_ end if
  239. ) ;_ end progn
  240.       ) ;_ end progn (if)
  241.     ) ;_ end defun ea:chg_color_ltyp_0
  242.     ;;修改属性块的属性实体及SEQEND, 属性只能是最外层, mark 块内/非块内标志
  243.     (defun ea:ChgAttBlk (blk mark / seqent attlst)
  244.       (setq attlst (vlax-safearray->list
  245.        (vlax-variant-value (vla-getattributes blk))
  246.      )
  247.       )
  248.       (mapcar '(lambda (x)
  249.    (if (vl-position (vla-get-layer x ) llyr)
  250.      (ea:chg_layer_color_ltyp_0 x mark)
  251.    )
  252.         )
  253.        attlst
  254.       )
  255.       (if (vl-position
  256.      (vlax-get-property
  257.        (setq
  258.   seqent (vlax-ename->vla-object
  259.     (entnext
  260.       (vlax-vla-object->ename (last attlst))
  261.     )
  262.          )
  263.        )
  264.        'layer
  265.      )
  266.      llyr
  267.    )
  268. (vlax-put-property seqent 'layer nlyr)
  269.       ) ;_ 修改 SEQEND 实体
  270.       (if (and (= tf1 "0")
  271.         (/= (vla-get-linetype seqent ) "BYLAYER")
  272.    )
  273. (vla-put-linetype seqent  "BYLAYER")
  274.       )
  275.     ) ;_end defun ea:chgattblk
  276.     ;;**************************************************************************************
  277.     ;;主程序
  278.     (if (and (/= llyr "") (/= nlyr ""))
  279.       (progn
  280. (if (not blocks)
  281.    (setq blocks (vla-get-blocks thisdrawing ))
  282. )
  283. (if (not layers)
  284.    (setq layers (vla-get-layers thisdrawing ))
  285. )
  286. (setq t0 (ea:get-utime))
  287. (if (not (tblsearch "layer" nlyr))
  288.    (vla-add layers nlyr)
  289. )
  290. ;;(vla-startundomark thisdrawing)
  291. (vlax-map-collection
  292.    layers
  293.    '(lambda (x) (vla-put-lock x  :vlax-false))
  294. )
  295. ;;有一种颜色无法保留
  296. (setq nl     (mapcar 'atoi (ea:string_parse llyr " "))
  297.        filter (ea:string_unparse
  298.          (setq llyr (mapcar '(lambda (x) (nth x name)) nl))
  299.          ","
  300.        )
  301. ) ;_end setq
  302. (if (not (vl-position "0" llyr))
  303.    (setq nllyr (append llyr '("0")))
  304.    (setq nllyr llyr)
  305. )
  306. (setq l (vla-get-count blocks ))
  307. (if (= tf "1") ;_ 保留颜色时提取对应的颜色列表
  308.    (setq llyrc
  309.    (mapcar
  310.      '(lambda (x / col mod bkname)
  311.         (if _$ver
  312.    (cons x (vla-get-truecolor (vla-item layers x) ))   
  313.    (cons x (cdr (assoc 62 (tblsearch "layer" x))))
  314.         ) ;_ end if
  315.       ) ;_ end lambda
  316.      (if (not (vl-position nlyr nllyr))
  317.        (append (list nlyr) nllyr)
  318.        nllyr
  319.      )
  320.    ) ;_end mapcar
  321.    ) ;_ end setq
  322. ) ;_ end if
  323. (if (= tf1 "1")
  324.    (setq lt
  325.    (mapcar '(lambda (x)
  326.        (cons x (cdr (assoc 6 (tblsearch "layer" x))))
  327.      )
  328.     (if (not (vl-position nlyr nllyr))
  329.       (append (list nlyr) nllyr)
  330.       nllyr
  331.     )
  332.    )
  333.    )
  334. )
  335. ;;处理实体
  336. (ea:clearcset)
  337. (if (ssget "x"
  338.      (list '(-4 . "<or")
  339.     '(66 . 1)
  340.     '(-4 . "<and")
  341.     (cons 8 filter)
  342.     '(-4 . "<not")
  343.     '(0 . "ACAD_PROXY_ENTITY")
  344.     '(-4 . "not>")
  345.     '(-4 . "and>")
  346.     '(-4 . "or>")
  347.      )
  348.      ) ;_ end ssget
  349.    (progn
  350.      (setq l (+ l
  351.          (vlax-get-property
  352.     (setq cset (vla-get-activeselectionset
  353.           thisdrawing
  354.         )
  355.     )
  356.     'count
  357.          )
  358.       )
  359.     n 1
  360.      )
  361.      (vlax-map-collection
  362.        cset
  363.        '(lambda (x / bbn)
  364.    (Ea:pross n l)
  365.    (cond
  366.      ((= (vla-get-objectname x ) "AcDbBlockReference")
  367.       (if (vl-position (vla-get-layer x) llyr)
  368.         (progn
  369.    (ea:chg_layer_color_ltyp_0 x nil)   
  370.    (if (not blst)
  371.      (setq blst
  372.      (list (setq
  373.       bbn (vla-get-name x )
  374.            )
  375.      )
  376.      )
  377.      (if (not (vl-position
  378.          (setq
  379.            bbn (vla-get-name x)
  380.          )
  381.          blst
  382.        )
  383.          )
  384.        (setq blst (append blst (list bbn)))
  385.      )
  386.    ) ;_ 只记录了最外层块
  387.         )
  388.       )
  389.       (if (= (vla-get-hasattributes  x) :vlax-true)
  390.         (ea:chgattblk x nil)
  391.       )
  392.      )
  393.      (t (ea:chg_layer_color_ltyp_0 x nil))
  394.    )
  395.    (setq n (1+ n))
  396.         )
  397.      )
  398.    ) ;_ while
  399. ) ;_ end progn
  400. ;;修改图块定义, 保留颜色仅涉及 块内 Bylayer 0 层是否改为 acByblock
  401. (vlax-map-collection
  402.    (vlax-get-property thisdrawing 'blocks)
  403.    '(lambda (i / bn e tmp)
  404.       (if
  405.         (and
  406.    (setq bn (strcase (vlax-get-property i 'name)))
  407.    (not (wcmatch bn "`**_SPAC*"))
  408.    (/= (vla-get-count i) 0)
  409.         )
  410.   ;;(vlax-map-collection
  411.   (if (vl-position bn blst);_ in ssget block
  412.     (vlax-map-collection
  413.       i
  414.       '(lambda (e / etyp lay bbn)
  415.          (setq etyp (vla-get-objectname e)
  416.         lay  (vla-get-layer e)
  417.          )
  418.          (cond
  419.     ((and (wcmatch etyp "*Block*")
  420.           (not (vl-position
  421.           (strcase (vla-get-name e))
  422.           blst
  423.         )
  424.           )
  425.           (vl-position lay llyr)
  426.      )
  427.      (if (not 0_in)
  428.        (setq 0_in (list (vla-get-name e)))
  429.        (if (not (vl-position
  430.            (setq bbn (vla-get-name e))
  431.            0_in
  432.          )
  433.     )
  434.          (setq 0_in (append (list bbn) 0_in))
  435.        )
  436.      )
  437.      (ea:chg_layer_color_ltyp_0 e t)
  438.      (if (= (vlax-get-property e 'hasattributes)
  439.      :vlax-true
  440.          )
  441.        (ea:chgattblk e t)
  442.      )
  443.     )
  444.     ((vl-position lay llyr)
  445.      (ea:chg_layer_color_ltyp_0 e t)
  446.     )
  447.     (t)
  448.          )
  449.        )
  450.     ) ;_ end vlax-map-collection
  451.     (vlax-map-collection ;_ not in ssget 但可能在 blst 引用内(0_in)
  452.       i
  453.       '(lambda (e / etyp lay)
  454.          (setq etyp (vla-get-objectname e)
  455.         lay  (vla-get-layer e)
  456.          )
  457.          (cond
  458.     ((vl-position lay llyr)
  459.      (cond
  460.        ((wcmatch etyp "*Block*")
  461.         (ea:chg_layer_color_ltyp_0 e t)
  462.         (if (not (vl-position
  463.      (strcase (vla-get-name e))
  464.      blst
  465.           )
  466.      )
  467.           (if (not 0_in)
  468.      (setq 0_in (list (vla-get-name e)))
  469.      (if
  470.        (not (vl-position
  471.        (setq bbn (vla-get-name e))
  472.        0_in
  473.      )
  474.        )
  475.         (setq
  476.           0_in (append (list bbn) 0_in)
  477.         )
  478.      )
  479.           )
  480.         )
  481.         (if
  482.           (= (vlax-get-property e 'hasattributes)
  483.       :vlax-true
  484.           )
  485.     (ea:chgattblk e t)
  486.         )
  487.        )
  488.        ((/= lay "0")
  489.         (ea:chg_layer_color_ltyp_0 e t)
  490.        )
  491.        (t)
  492.      )
  493.     )
  494.     ((and (= lay "0") ;_ 仅保留 0 层实体
  495.           (not (vl-position lay llyr))
  496.      )
  497.       (if (not 0_in)
  498.         (setq 0_in (list bn))
  499.         (if (not (vl-position bn 0_in))
  500.           (setq
  501.      0_in (append (list bn) 0_in)
  502.           )
  503.         )
  504.       )
  505.       (setq nn  (read bn)
  506.      tmp (eval nn)
  507.       )
  508.       (if (not tmp)
  509.         (set nn (list e))
  510.         (set nn (cons e tmp))
  511.       )
  512.     ) ;_ end if
  513.     (t)
  514.          );_ end if
  515.        );_ end lambda
  516.     ) ;_ end vlax-map-collection
  517.   ) ;_ end if
  518.       ) ;_ end if
  519.     ) ;_ end lambda
  520. ) ;_ 结束处理块定义
  521. ;;处理被非选择图块且被引用并在 llyr 图层之块定义内的 0 实体
  522. (if 0_in
  523.    (progn
  524.      (setq 0colorobj (vla-get-truecolor (vla-item layers"0")))
  525.      (vla-put-colorindex 0colorobj acByblock)
  526.      (mapcar
  527.        '(lambda (x / 0lst)
  528.    (if (not (setq 0lst (eval (read x))))
  529.      (mapcar '(lambda (e0)
  530.          (if _$ver
  531.     (vla-put-truecolor e0 0colorobj)
  532.     (vla-put-color e0 0)
  533.          )
  534.        )
  535.       olst
  536.      )
  537.    )
  538.         )
  539.        0_in
  540.      )
  541.    )
  542. )
  543. (setvar "clayer" "0")
  544. (vla-purgeall thisdrawing)
  545. ;;更新块引用
  546. (if (setq s (ssget "x" (list (cons 8 nlyr) '(0 . "INSERT"))))
  547.    (progn
  548.      (setq sl (sslength s))
  549.      (while (> sl 0)
  550.        (entupd (ssname s (setq sl (1- sl))))
  551.      )
  552.    ) ;_ end progn
  553. ) ;_ end if
  554. ;;(vla-endundomark thisdrawing)
  555. (setq llyr   nil
  556.        name   (ea:table "layer")
  557.        blocks (vlax-get-property thisdrawing 'blocks)
  558.        layers (vlax-get-property thisdrawing 'layers)
  559. )
  560. (if fillc
  561.    (progn
  562.      (setq ll (entget (tblobjname "layer" nlyr))
  563.     ll (vl-remove-if
  564.          '(lambda (x)
  565.      (vl-position (car x) '(62 420 430)))
  566.          ll
  567.        )
  568.      )
  569.      (entmod (append ll fillc))
  570.    )
  571. )
  572. (if t0
  573.    (progn
  574.      (setq t1 (ea:get-utime))
  575.      (princ
  576.        (strcat "\n成功转换至 " nlyr " 图层,  耗时(secs): ")
  577.      )
  578.      (princ (- t1 t0))
  579.    )
  580. )
  581. (if all_0 (mapcar '(lambda (x) (set x nil)) all_0))
  582.       ) ;_ end progn
  583.     ) ;_end if
  584.   ) ;_ end dufun ea:translyr
  585.   ;;预览
  586.   (defun ea:pre (/ nl layers str)
  587.     (if (and (/= llyr nil) (/= llyr ""))
  588.       (progn
  589. (vla-startundomark thisdrawing)
  590. (setq nl     (mapcar 'atoi (ea:string_parse llyr " "))
  591.        nl     (mapcar '(lambda (x) (nth x name)) nl)
  592. )
  593. (vlax-map-collection
  594.    (vlax-get-property thisdrawing 'layers)
  595.    '(lambda (l)
  596.       (if (vl-position (vlax-get-property l 'name) nl)
  597.         (progn
  598.    (if (= (vlax-get-property l 'layeron) :vlax-false)
  599.      (vlax-put-property  l 'layeron :vlax-true)
  600.    )
  601.    (if (= (vlax-get-property l 'freeze) :vlax-true)
  602.      (vlax-put-property l 'freeze :vlax-false)
  603.    )
  604.         )
  605.         (vlax-put-property l 'layeron :vlax-false)
  606.       )
  607.     )
  608. )
  609. (vla-endundomark thisdrawing)
  610. (setq str (getstring "\n回车退出...."))
  611. (vl-cmdf ".u")
  612.       )
  613.     ) ;_end if
  614.     (princ)
  615.   ) ;_ end defun  ea:per
  616.   ;;选择合并实体, 支持嵌套在块内图层?
  617.   (defun getssLyr (/ ss ssl lyr slyr slst)
  618.     (princ "\n选择要合并图层实体<退出>...")
  619.     (if (setq ss (ssget))
  620.       (progn
  621. (setq ssl (sslength ss))
  622. (while (> ssl 0)
  623.    (setq
  624.      lyr
  625.       (cdr (assoc 8 (entget (ssname ss (setq ssl (1- ssl))))))
  626.    )
  627.    (if slyr
  628.      (if (not (vl-position lyr slyr))
  629.        (setq slyr (cons lyr slyr))
  630.      )
  631.      (setq slyr (list lyr))
  632.    )
  633. ) ;_ end while
  634. (setq slst (mapcar '(lambda (l) (vl-position l name))
  635.       slyr
  636.      )
  637. )
  638. (if llyr
  639.    (setq slst
  640.    (append slst (mapcar 'atoi (ea:string_parse llyr " ")))
  641.    )
  642. )
  643. (setq llyr (ea:string_unparse
  644.        (mapcar 'vl-princ-to-string
  645.         (vl-sort slst '<)
  646.        )
  647.        " "
  648.      )
  649. )
  650.       ) ;_ end progn
  651.     ) ;_ end if
  652.   ) ;_ end dufun
  653.   ;;获取当前颜色 l 层
  654.   (defun ea:getcecolor (l / color el inc tc dc le)
  655.     (if (not l)
  656.       (progn
  657. (setq color (getvar "cecolor"))
  658. (cond
  659.    ((= (type (read color)) 'INT);_ ACI
  660.     (list (cons 62 (read color)))
  661.    )
  662.    ((wcmatch color "RGB:*");_ truecolor
  663.     (setq inc
  664.     (RGBtoACI
  665.       (setq
  666.         tc
  667.          (mapcar
  668.     'atoi
  669.     (ea:string_parse (vl-string-trim "RGB:" color) ",")
  670.          )
  671.       )
  672.     )
  673.     )
  674.     (list (cons 62 inc) (cons 420 (RGBtoOLE_color tc)))
  675.    )
  676.    ((= color "BYLAYER")
  677.     (setq el  (entget (tblobjname "layer" (getvar "clayer")))
  678.    inc (assoc 62 el)
  679.    tc  (assoc 420 el)
  680.    dc  (assoc 430 el)
  681.     )
  682.     (cond
  683.       (dc (list inc tc dc))
  684.       (tc (list inc tc))
  685.       (t (list inc))
  686.     )
  687.    )
  688.    ((= color "BYBLOCK")
  689.     (setq color '(62 . 7))
  690.    )
  691. );_ end cond
  692.       );_ end progn
  693.       (if (setq le (tblobjname "layer" l))
  694. (progn
  695.    (setq el  (entget le)
  696.   inc (assoc 62 el)
  697.   tc  (assoc 420 el)
  698.   dc  (assoc 430 el)
  699.    )
  700.    (cond
  701.      (dc (list inc tc dc))
  702.      (tc (list inc tc))
  703.      (t (list inc))
  704.    )
  705. )
  706. (ea:getcecolor nil)
  707.       )
  708.     )
  709.   ) ;_ end defun ea:getcecolor
  710.   ;;填充默认颜色
  711.   (defun ea:fillcolor (/ cc width height cl)
  712.     (cond
  713.       (fillc    ;acad_colordlg
  714.        (setq cc (abs (cdar fillc)))
  715.       )
  716.       (nlyr
  717.        (setq cc (abs (cdar (ea:getcecolor nlyr))))
  718.       )
  719.       (t
  720.        (setq cc (abs (cdar (ea:getcecolor nil))))
  721.       )
  722.     )
  723.     (setq width  (dimx_tile "col")
  724.    height (dimy_tile "col")
  725.     )
  726.     (start_image "col")
  727.     (fill_image 0 0 width height cc) ;1 = AutoCAD red.
  728.     (end_image)
  729.   ) ;_ end defun
  730.   ;;修改颜色按钮
  731.   (defun ea:chgcolor (/ c l)
  732.     (setq c (ea:getcecolor nlyr))
  733.     (setq fillc (if _$ver
  734.     (cond
  735.       ((= (setq l (length c)) 1);_ aci
  736.        (acad_truecolordlg (cdar c))
  737.       )
  738.       ((= l 2);_ truecolor
  739.        (acad_truecolordlg (cadr c))
  740.       )
  741.       (t (acad_truecolordlg (last c)));_ dict
  742.     )
  743.     (acad_colordlg (car c))
  744.   )
  745.     ) ;_ end setq
  746.   ) ;_ end defun
  747.   (defun myerr (msg /)
  748.     (if (or (/= msg "*函数已取消*")
  749.      (= msg "*函数已取消*")
  750. )
  751.       (princ "\n*取消*")
  752.     )
  753.     (if 0_in
  754.       (mapcar '(lambda (x) (set (read x) nil)) 0_in)
  755.     )
  756.     (setq 0_in nil)
  757.     (vla-endundomark thisdrawing)
  758.     (setq *error* olderr)
  759.     (princ)
  760.   ) ;_end deufn
  761.   ;;***********************************************************
  762.   ;;主程序
  763.   (setq oAcad     (vlax-get-acad-object)
  764. thisdrawing (vlax-get-property oAcad 'activedocument)
  765. _$ver     (> (atof (getvar "acadver")) 16.)
  766. olderr     *error*
  767. *error*     myerr
  768.   )
  769.   (vla-startundomark thisdrawing)
  770.   (if (setq nullss (ssget "x" '((0 . "*text") (1 . ""))))
  771.     (vl-cmdf ".erase" nullss "")
  772.   )
  773.   ;(vla-purgeall thisdrawing)
  774.   (if (not _ealyrtr_id)
  775.     (setq _ealyrtr_id (load_dialog "D:/lyrtr.dcl"))
  776.   )
  777.   (setq what_next 2)
  778.   (while (>= what_next 2)
  779.     (if (not name)
  780.       (setq name (ea:table "layer"))
  781.     )
  782.     (if (not (new_dialog "ea_lyrtrans" _ealyrtr_id))
  783.       (exit)
  784.     )
  785.     (start_list "what")
  786.     (mapcar 'add_list name)
  787.     (end_list)
  788.     (start_list "Sel")
  789.     (mapcar 'add_list name)
  790.     (end_list)
  791.     (if llyr
  792.       (set_tile "what" llyr)
  793.     )
  794.     (if (and (/= nlyr "") nlyr)
  795.       (set_tile "Nlyr" nlyr)
  796.     )
  797.     (ea:fillcolor)
  798.     (if tf
  799.       (set_tile "color" tf)
  800.     )
  801.     (if tf1
  802.       (set_tile "ltyp" tf1)
  803.     )
  804.     (action_tile
  805.       "Trans"
  806.       (strcat
  807. "(princ "\n请稍候,处理进行中.....")"
  808. "(setq nlyr (get_tile "Nlyr"))"
  809. "(setq llyr (get_tile "what"))"
  810. "(setq tf (get_tile "color"))"
  811. "(setq tf1 (get_tile "ltyp"))"
  812. "(setq ltf (get_tile "lay"))"
  813. "(done_dialog 4)"
  814.        )
  815.     )
  816.     (action_tile "accept" "(done_dialog 1)")
  817.     (action_tile "lay" "(setq ltf $value)")
  818.     (action_tile "Nlyr" "(setq nlyr $value)")
  819.     (action_tile "color" "(setq tf $value)")
  820.     (action_tile "ltyp" "(setq tf1 $value)")
  821.     (action_tile
  822.       "col"
  823.       "(setq nlyr (get_tile "Nlyr"))(ea:chgcolor)(ea:fillcolor)(if fillc(set_tile "color" "0"))"
  824.     )
  825.     (action_tile
  826.       "Sel"
  827.       "(set_tile "Nlyr" (nth (atoi $value) name))"
  828.     )
  829.     (action_tile
  830.       "pre"
  831.       "(setq nlyr (get_tile "Nlyr"))(setq llyr (get_tile "what")) (done_dialog 5)"
  832.     )
  833.     (action_tile
  834.       "list"
  835.       "(setq llyr (get_tile "what"))(done_dialog 6)"
  836.     )
  837.     (action_tile
  838.       "what"
  839.       (strcat
  840. "(setq nlyr (get_tile "Nlyr"))"
  841. "(setq llyr $value)"
  842. "(if (= $reason 4)(progn (setq nlyr (get_tile "Nlyr"))(setq llyr $value)(done_dialog 5)))" ;_ double click
  843.       )
  844.     )
  845.     (setq what_next (start_dialog))
  846.     (cond
  847.       ((= what_next 4)
  848.        (ea:translyr)
  849.       )
  850.       ((= what_next 5)
  851.        (ea:pre)
  852.       )
  853.       ((= what_next 6)
  854.        (getsslyr)
  855.       )
  856.     )
  857.   ) ;_end while
  858.   (unload_dialog _ealyrtr_id)
  859.   (vla-endundomark thisdrawing)
  860.   (vlax-release-object thisdrawing)
  861.   (vlax-release-object oAcad)
  862.   (if blocks (vlax-release-object blocks))
  863.   (if layers (vlax-release-object layers))
  864.   (if 0_in (mapcar '(lambda (x) (set (read x) nil)) 0_in))
  865.   (setq 0_in nil)
  866.   (setq *error* olderr)
  867.   (princ)
  868. ) ;_end defun
  869. (princ
  870.   "\n\t图层合并V2.3, 命令: Lyrt. BY eachy[www.xdcad.net]"
  871. )
  872. (princ)
请问一下为什么输入命令后窗口弹出后闪退呀?

本帖子中包含更多资源

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

x
"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2019-6-3 21:11 | 显示全部楼层
有人知道如何改一下可以把这两个文件直接放在d盘使用吗?或者怎么把他们合并到lsp

本帖子中包含更多资源

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

x

点评

缺少 vla-get-truecolor 函数  发表于 2020-2-15 04:59
此文件有多余闭括号,  发表于 2020-2-15 04:11
发表于 2020-2-15 05:07 | 显示全部楼层
合并了下,似乎缺少2个函数


本帖子中包含更多资源

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

x
发表于 2023-11-1 22:17 | 显示全部楼层
尘缘一生 发表于 2020-2-15 05:07
合并了下,似乎缺少2个函数

加载运行没反应
发表于 2024-5-17 10:51 | 显示全部楼层
尘缘一生 发表于 2020-2-15 05:07
合并了下,似乎缺少2个函数

没跑起来
发表于 2024-5-17 10:53 | 显示全部楼层
图层合并可以直接laymgr命令或者在layer命令界面合并,没必要写代码
发表于 2024-5-19 23:31 | 显示全部楼层
kozmosovia 发表于 2024-5-17 10:53
图层合并可以直接laymgr命令或者在layer命令界面合并,没必要写代码

laymgr命令不好用啊,用.chprop就很快,一句command解决
发表于 2024-5-20 00:40 | 显示全部楼层
jun470 发表于 2024-5-19 23:31
laymgr命令不好用啊,用.chprop就很快,一句command解决

中文真好,改图层==合并图层
发表于 2024-5-20 22:49 | 显示全部楼层
kozmosovia 发表于 2024-5-20 00:40
中文真好,改图层==合并图层

我自己就这么用的,改到一起就行,看需求吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-2 05:30 , Processed in 0.194302 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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