I want post the lisp code,but
"The text that you have entered is too long (20593 characters). Please shorten it to 15000 characters long."
Can download Attached Files in #1
Part1.
- ;by eachy ;flowerson edit(vl-load-com)(if (>= (atof (getvar "acadver")) 16.0) (vl-arx-import "acapp.arx") (vl-arx-import "acadapp.arx"));|The global variable nlyr: new layer llyr: conversion list name: layer list fillc : new layer colour tf : keep colour "1" keep "0" Don't keep tf1 : keep linear "1" keep "0" Don't keep ltf : Ignore the block layer 0 "1" Ignore "0" modify|;(defun c:TEST (/ ea:string_parse ea:string_unparse ea:pross ea:get-utime RGBtoOLE_color OLEtoRGB_color RGBtoACI ea:getcecolor ea:chglyrcolor ea:translyr ea:chgcolor ea:fillcolor ea:pre ea:table getsslyr myerr mknewlyr ea:clearcset thisdrawing blocks layers name nullss olderr ltf nlyr llyr fillc tf tf1 _$ver _ealyrtr_id what_next oAcad x tmp bn ) ;|(if (or (> (atoi (rtos (getvar "cdate") 2 0)) 20041231) (< (atoi (rtos (getvar "cdate") 2 0)) 20040906) ) (vla-eval (vlax-get-acad-object) (strcat"MsgBox "\nAuthor: Eachy\n\nhttp:\\\\www.xdcad.net""", ""vbExclamation+vbSystemModal"", """Layer Merge V2.3 "" ) ) ;_ end eval ) ;_ end if|; (defun ea:table (s / d r) (while (setq d (tblnext s (null d))) (setq r (cons (cdr (assoc 2 d)) r)) ) (acad_strlsort (reverse r)) ) (defun ea:string_parse (str delimiter / post strlst) (if str (progn(setq strlst '())(while (vl-string-search delimiter str) (setq post (vl-string-search delimiter str)) (setq strlst (append strlst (list (substr str 1 post)))) (setq str (substr str (+ post 2))))(vl-remove "" (append strlst (list str))) ) ) ;_ end if ) ;_ end defun ea:string_pase (defun ea:string_unparse (lst delimiter / return) (setq return "") (foreach str lst (setq return (strcat return delimiter str)) ) (substr return 2) ) ;;The progress bar (defun Ea:pross (k l) (grtext -2 (strcat "Has been completed" (rtos (/ (* 100.0 k) l) 2 0 ) "%...." ) ) ) (defun ea:get-utime () (* 86400 (getvar "tdusrtimer")) ) ;; Convert a list of RGB to TrueColor ;; (RGBtoOLE_color '(118 118 118)) (defun RGBtoOLE_color (RGB-codes / r g b) (setq r (lsh (car RGB-codes) 16)) (setq g (lsh (cadr RGB-codes) ) (setq b (caddr RGB-codes)) (+ (+ r g) b) ) ;;Truecolor -> rgb (defun OLEtoRGB_color (OLE_color / r g b) (setq r (lsh OLE_color -16)) (setq g (lsh (lsh OLE_color 16) -24)) (setq b (lsh (lsh OLE_color 24) -24)) (strcat "RGB:" (vl-princ-to-string r) "," (vl-princ-to-string g) "," (vl-princ-to-string b) ;(list r g b)) ) ) ;; (defun RGBtoACI (RGB-codes / colorobj) (setq ColorObj (vla-GetInterfaceObject oAcad "AutoCAD.AcCmColor.16") ) (vlax-invoke ColorObj 'setRGB (car RGB-codes) (cadr RGB-codes) (caddr RGB-codes) ) (vlax-get-property ColorObj 'ColorIndex) ) (defun ea:Clearcset (/ cset) (if (not (vl-catch-all-error-p (setq cset (vl-catch-all-apply 'vla-item (list (vla-get-selectionsets thisdrawing) "CURRENT" ) ) ) )) (vla-delete cset) ) (princ) ) ;;************************************************************************** ;;conversion main code (defun ea:translyr (/ ea:chg_layer_color_ltyp_0 ea:chgattblk ea:chg_ssget_blockdef ea:chg_not_ssget_blockdef llyrc lt t0 nl filter cset l n s sl t1 blst ll lt x nllyr 0colorobj 0_in e0 all_0 nn tmp ) (defun ea:chg_layer_color_ltyp_0 (obj mark / alyr cl colobj olt) (if (/= (cdr (assoc 0 (entget (vlax-vla-object->ename obj ) ) ) ) "ACAD_PROXY_ENTITY" ) (progn (setq alyr (vla-get-layer obj)) (if _$ver (progn (setq colobj (vla-get-truecolor obj) cl (vla-get-colorindex colobj ) ) (if (= cl 256) ;_ bylayer (setq colobj (cdr (assoc alyr llyrc))) ) ) ; (if (= (setq cl (vla-get-color obj )) 256) (setq cl (cdr (assoc alyr llyrc))) ) ) ;;modify layer (if (and (/= alyr nlyr) (not (and mark (= alyr "0") (= ltf "1"))) ) (vla-put-layer obj nlyr) ) ;_ end if ;;Restore color (if (= tf "1") ;_keep (cond ((and mark (= alyr "0") ; (= cl 256) ;_ bylayer ) (if _$ver (progn (vla-put-colorindex colobj acByblock) ; (vla-put-truecolor obj ' colobj) ) (vla-put-color obj 0) ) ;_ byblock ) ((and (/= alyr nlyr) (= cl 256)) ; (if _$ver (vla-put-truecolor obj colobj) (vla-put-color obj cl) ) ;_ end if ) (t) ) ;_ end cond (if (and _$ver (/= cl 256) ) (progn (vla-put-colorindex colobj 256);_ bylayer (vla-put-truecolor obj colobj) ) (vla-put-color obj 256) ) ) ;_end if (if (= tf1 "1") (if (and (= (setq olt (vla-get-linetype obj )) "BYLAYER" ) (/= olt "BYBLOCK") (vlax-property-available-p obj 'linetype t) ) (vlax-put-property obj 'linetype (cdr (assoc alyr lt))) ) (if (and (/= (vla-get-linetype obj ) "BYLAYER") (vlax-property-available-p obj 'linetype t) ) (vla-put-linetype obj ' "BYLAYER") ) ) ;_ end if) ;_ end progn ) ;_ end progn (if) ) ;_ end defun ea:chg_color_ltyp_0 (defun ea:ChgAttBlk (blk mark / seqent attlst) (setq attlst (vlax-safearray->list (vlax-variant-value (vla-getattributes blk)) ) ) (mapcar '(lambda (x) (if (vl-position (vla-get-layer x ) llyr) (ea:chg_layer_color_ltyp_0 x mark) ) ) attlst ) (if (vl-position (vlax-get-property (setq seqent (vlax-ename->vla-object (entnext (vlax-vla-object->ename (last attlst)) ) ) ) 'layer ) llyr )(vlax-put-property seqent 'layer nlyr) ) ; (if (and (= tf1 "0") (/= (vla-get-linetype seqent ) "BYLAYER") )(vla-put-linetype seqent "BYLAYER") ) ) ;_end defun ea:chgattblk ;;main code (if (and (/= llyr "") (/= nlyr "")) (progn (if (not blocks) (setq blocks (vla-get-blocks thisdrawing )))(if (not layers) (setq layers (vla-get-layers thisdrawing )))(setq t0 (ea:get-utime))(if (not (tblsearch "layer" nlyr)) (vla-add layers nlyr));;(vla-startundomark thisdrawing)(vlax-map-collection layers '(lambda (x) (vla-put-lock x :vlax-false)))(setq nl (mapcar 'atoi (ea:string_parse llyr " ")) filter (ea:string_unparse (setq llyr (mapcar '(lambda (x) (nth x name)) nl)) "," )) ;_end setq(if (not (vl-position "0" llyr)) (setq nllyr (append llyr '("0"))) (setq nllyr llyr))(setq l (vla-get-count blocks ))(if (= tf "1") ; (setq llyrc (mapcar '(lambda (x / col mod bkname) (if _$ver (cons x (vla-get-truecolor (vla-item layers x) )) (cons x (cdr (assoc 62 (tblsearch "layer" x)))) ) ;_ end if ) ;_ end lambda (if (not (vl-position nlyr nllyr)) (append (list nlyr) nllyr) nllyr ) ) ;_end mapcar ) ;_ end setq ) ;_ end if (if (= tf1 "1") (setq lt (mapcar '(lambda (x) (cons x (cdr (assoc 6 (tblsearch "layer" x)))) ) (if (not (vl-position nlyr nllyr)) (append (list nlyr) nllyr) nllyr ) ) ))(ea:clearcset)(if (ssget "x" (list '(-4 . "") ) ) ;_ end ssget (progn (setq l (+ l (vlax-get-property (setq cset (vla-get-activeselectionset thisdrawing ) ) 'count ) ) n 1 ) (vlax-map-collection cset '(lambda (x / bbn) (Ea:pross n l) (cond ((= (vla-get-objectname x ) "AcDbBlockReference") (if (vl-position (vla-get-layer x) llyr) (progn (ea:chg_layer_color_ltyp_0 x nil) (if (not blst) (setq blst (list (setq bbn (vla-get-name x ) ) ) ) (if (not (vl-position (setq bbn (vla-get-name x) ) blst ) ) (setq blst (append blst (list bbn))) ) ) ) ) (if (= (vla-get-hasattributes x) :vlax-true) (ea:chgattblk x nil) ) ) (t (ea:chg_layer_color_ltyp_0 x nil)) ) (setq n (1+ n)) ) ) ) ;_ while) ;_ end progn
|