srinak47 Posted January 24, 2014 Posted January 24, 2014 (edited) Hi Can any one edit this Lisp.. This Lisp converting my block elements(elements inside the block) to desired layer but the block(main block) layer is remain same... i would like to change block elements, nested block elements and the block to change in "0" or "Desired Layer" i just dont know how to change the block layer... (defun c:norm (/ *error* adoc lst_layer func_restore-layers) (defun *error* (msg) (func_restore-layers) (vla-endundomark adoc) (princ msg) (princ) ) ;_ end of defun (defun func_restore-layers () (foreach item lst_layer (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))) (vl-catch-all-apply '(lambda () (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))) ) ;_ end of vla-put-freeze ) ;_ end of lambda ) ;_ end of vl-catch-all-apply ) ;_ end of foreach ) ;_ end of defun (vl-load-com) (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ) ;_ end of vla-startundomark (if (and (not (vl-catch-all-error-p (setq selset (vl-catch-all-apply (function (lambda () (ssget '((0 . "INSERT"))) ) ;_ end of lambda ) ;_ end of function ) ;_ end of vl-catch-all-apply ) ;_ end of setq ) ;_ end of vl-catch-all-error-p ) ;_ end of not selset ) ;_ end of and (progn (vlax-for item (vla-get-layers adoc) (setq lst_layer (cons (list item (cons "lock" (vla-get-lock item)) (cons "freeze" (vla-get-freeze item)) ) ;_ end of list lst_layer ) ;_ end of cons ) ;_ end of setq (vla-put-lock item :vlax-false) (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)) ) ;_ end of vl-catch-all-apply ) ;_ end of vlax-for (foreach blk_def (mapcar (function (lambda (x) (vla-item (vla-get-blocks adoc) x) ) ;_ end of lambda ) ;_ end of function ((lambda (/ res) (foreach item (mapcar (function (lambda (x) (vla-get-name (vlax-ename->vla-object x) ) ;_ end of vla-get-name ) ;_ end of lambda ) ;_ end of function ((lambda (/ tab item) (repeat (setq tab nil item (sslength selset) ) ;_ end setq (setq tab (cons (ssname selset (setq item (1- item)) ) ;_ end of ssname tab ) ;_ end of cons ) ;_ end of setq ) ;_ end of repeat tab ) ;_ end of lambda ) ) ;_ end of mapcar (if (not (member item res)) (setq res (cons item res)) ) ;_ end of if ) ;_ end of foreach (reverse res) ) ;_ end of lambda ) ) ;_ end of mapcar (vlax-for ent blk_def (vla-put-layer ent "0") (vla-put-color ent 0) (vla-put-lineweight ent aclnwtbyblock) (vla-put-linetype ent "byblock") ) ;_ end of vlax-for ) ;_ end of foreach (func_restore-layers) (vla-regen adoc acallviewports) ) ;_ end of progn ) ;_ end of if (vla-endundomark adoc) (princ) ) ;_ end of defun Edited January 31, 2014 by srinak47 author Quote
Tharwat Posted January 24, 2014 Posted January 24, 2014 Are you after changing all the objects in ALL blocks in a drawing to one Specific Layer Name ? Quote
srinak47 Posted January 24, 2014 Author Posted January 24, 2014 eg.. i have to select all furniture objects and furniture blocks(even the nested blocks) to specific layer name... Same thing i have to do for mechanical and plumbing and so on... Quote
ymg3 Posted January 24, 2014 Posted January 24, 2014 Have you tried this routine by Gille Chanteau: Edit_Block ymg Quote
marko_ribar Posted January 24, 2014 Posted January 24, 2014 Hi, ymg... I've checked Gile's code and I did find some lack... After scaling option on all references, block isn't updated in Current Drawing block collections, so I had to add two lines in the end of routine : (command "_.bedit" "Current Drawing") (command "_.bclose") Beside this, I've successfully implemented DCL into LSP routine so you don't need it, it's all inside lisp - you can easily add this routine into Startup Suite which is what I did... Routine was nicely written, all kudos to Gilles Chanteaux... M.R. (I'll attach my version, for those that want to download it and use it) editblock.lsp Quote
ymg3 Posted January 24, 2014 Posted January 24, 2014 Thanks Marko, Gilles has always been a great! contributor. ymg Quote
marko_ribar Posted January 24, 2014 Posted January 24, 2014 Yes, this is all OK, but if you check routine it does not answer on OP's request... OP, look for marked highlighted line and change to desired value to suit your needs... (defun c:norm ( / *error* adoc lst_layer func_restore-layers tab ) (defun *error* (msg) (func_restore-layers) (vla-endundomark adoc) (princ msg) (princ) ) ;_ end of defun (defun func_restore-layers () (foreach item lst_layer (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))) (vl-catch-all-apply '(lambda () (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))) ) ;_ end of vla-put-freeze ) ;_ end of lambda ) ;_ end of vl-catch-all-apply ) ;_ end of foreach ) ;_ end of defun (vl-load-com) (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ) ;_ end of vla-startundomark (if (and (not (vl-catch-all-error-p (setq selset (vl-catch-all-apply (function (lambda () (ssget '((0 . "INSERT"))) ) ;_ end of lambda ) ;_ end of function ) ;_ end of vl-catch-all-apply ) ;_ end of setq ) ;_ end of vl-catch-all-error-p ) ;_ end of not selset ) ;_ end of and (progn (vlax-for item (vla-get-layers adoc) (setq lst_layer (cons (list item (cons "lock" (vla-get-lock item)) (cons "freeze" (vla-get-freeze item)) ) ;_ end of list lst_layer ) ;_ end of cons ) ;_ end of setq (vla-put-lock item :vlax-false) (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)) ) ;_ end of vl-catch-all-apply ) ;_ end of vlax-for (foreach blk_def (mapcar (function (lambda (x) (vla-item (vla-get-blocks adoc) x) ) ;_ end of lambda ) ;_ end of function ((lambda (/ res) (foreach item (mapcar (function (lambda (x) (vla-get-name (vlax-ename->vla-object x) ) ;_ end of vla-get-name ) ;_ end of lambda ) ;_ end of function ((lambda (/ item) (repeat (setq tab nil item (sslength selset) ) ;_ end setq (setq tab (cons (ssname selset (setq item (1- item)) ) ;_ end of ssname tab ) ;_ end of cons ) ;_ end of setq ) ;_ end of repeat tab ) ;_ end of lambda ) ) ;_ end of mapcar (if (not (member item res)) (setq res (cons item res)) ) ;_ end of if ) ;_ end of foreach (reverse res) ) ;_ end of lambda ) ) ;_ end of mapcar (vlax-for ent blk_def (vla-put-layer ent "0") (vla-put-color ent 0) (vla-put-lineweight ent aclnwtbyblock) (vla-put-linetype ent "byblock") ) ;_ end of vlax-for ) ;_ end of foreach (func_restore-layers) (vla-regen adoc acallviewports) ) ;_ end of progn ) ;_ end of if (vla-endundomark adoc) (foreach bl tab (vla-put-layer (vlax-ename->vla-object bl) "0") [highlight];;; => Change "0" to desired Layer name ;;;[/highlight] ) (princ) ) ;_ end of defun M.R. Quote
flyfox1047 Posted January 25, 2014 Posted January 25, 2014 Thanks Marko, Gilles has always been a great! contributor. ymg I seriously agree! Quote
srinak47 Posted January 25, 2014 Author Posted January 25, 2014 (edited) Hmmm , i want to change the layer of all objects inside blocks and nested blocks as well the block also go in to the same layer... Am not Tested Yet!!! will Test it 12 hrs from now.... Edited January 31, 2014 by srinak47 Not Tested Yet!! Quote
srinak47 Posted January 26, 2014 Author Posted January 26, 2014 (edited) Hey m8 thanks... this what am seeking to modify... thanks... BUT this lisp is not considering the Nested Block... i want nested lisp to change to "0" layer or Desired Layer..... Yeah You Really Rock.... You got what i really wanted and failed to do ... it work awesome ... please add the line to Change to NESTED Block.... Sorry FOR MY ENGLISH ( Am not originated with this language ) Yes, this is all OK, but if you check routine it does not answer on OP's request... OP, look for marked highlighted line and change to desired value to suit your needs... (defun c:norm ( / *error* adoc lst_layer func_restore-layers tab ) (defun *error* (msg) (func_restore-layers) (vla-endundomark adoc) (princ msg) (princ) ) ;_ end of defun (defun func_restore-layers () (foreach item lst_layer (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))) (vl-catch-all-apply '(lambda () (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))) ) ;_ end of vla-put-freeze ) ;_ end of lambda ) ;_ end of vl-catch-all-apply ) ;_ end of foreach ) ;_ end of defun (vl-load-com) (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ) ;_ end of vla-startundomark (if (and (not (vl-catch-all-error-p (setq selset (vl-catch-all-apply (function (lambda () (ssget '((0 . "INSERT"))) ) ;_ end of lambda ) ;_ end of function ) ;_ end of vl-catch-all-apply ) ;_ end of setq ) ;_ end of vl-catch-all-error-p ) ;_ end of not selset ) ;_ end of and (progn (vlax-for item (vla-get-layers adoc) (setq lst_layer (cons (list item (cons "lock" (vla-get-lock item)) (cons "freeze" (vla-get-freeze item)) ) ;_ end of list lst_layer ) ;_ end of cons ) ;_ end of setq (vla-put-lock item :vlax-false) (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)) ) ;_ end of vl-catch-all-apply ) ;_ end of vlax-for (foreach blk_def (mapcar (function (lambda (x) (vla-item (vla-get-blocks adoc) x) ) ;_ end of lambda ) ;_ end of function ((lambda (/ res) (foreach item (mapcar (function (lambda (x) (vla-get-name (vlax-ename->vla-object x) ) ;_ end of vla-get-name ) ;_ end of lambda ) ;_ end of function ((lambda (/ item) (repeat (setq tab nil item (sslength selset) ) ;_ end setq (setq tab (cons (ssname selset (setq item (1- item)) ) ;_ end of ssname tab ) ;_ end of cons ) ;_ end of setq ) ;_ end of repeat tab ) ;_ end of lambda ) ) ;_ end of mapcar (if (not (member item res)) (setq res (cons item res)) ) ;_ end of if ) ;_ end of foreach (reverse res) ) ;_ end of lambda ) ) ;_ end of mapcar (vlax-for ent blk_def (vla-put-layer ent "0") (vla-put-color ent 0) (vla-put-lineweight ent aclnwtbyblock) (vla-put-linetype ent "byblock") ) ;_ end of vlax-for ) ;_ end of foreach (func_restore-layers) (vla-regen adoc acallviewports) ) ;_ end of progn ) ;_ end of if (vla-endundomark adoc) (foreach bl tab (vla-put-layer (vlax-ename->vla-object bl) "0") [highlight];;; => Change "0" to desired Layer name ;;;[/highlight] ) (princ) ) ;_ end of defun M.R. Edited January 31, 2014 by srinak47 Quote
srinak47 Posted January 27, 2014 Author Posted January 27, 2014 (edited) Everything is good so far, i have fixed it... nested block is also changing to Desired/specified layer that will be Helpful for you guys (defun c:eq ( / *error* adoc lst_layer func_restore-layers tab ) (defun *error* (msg) (func_restore-layers) (vla-endundomark adoc) (princ msg) (princ) ) ;_ end of defun (defun func_restore-layers () (foreach item lst_layer (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))) (vl-catch-all-apply '(lambda () (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))) ) ;_ end of vla-put-freeze ) ;_ end of lambda ) ;_ end of vl-catch-all-apply ) ;_ end of foreach ) ;_ end of defun (vl-load-com) (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ) ;_ end of vla-startundomark (if (and (not (vl-catch-all-error-p (setq selset (vl-catch-all-apply (function (lambda () (ssget '((0 . "INSERT"))) ) ;_ end of lambda ) ;_ end of function ) ;_ end of vl-catch-all-apply ) ;_ end of setq ) ;_ end of vl-catch-all-error-p ) ;_ end of not selset ) ;_ end of and (progn (vlax-for item (vla-get-layers adoc) (setq lst_layer (cons (list item (cons "lock" (vla-get-lock item)) (cons "freeze" (vla-get-freeze item)) ) ;_ end of list lst_layer ) ;_ end of cons ) ;_ end of setq (vla-put-lock item :vlax-false) (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)) ) ;_ end of vl-catch-all-apply ) ;_ end of vlax-for (foreach blk_def (mapcar (function (lambda (x) (vla-item (vla-get-blocks adoc) x) ) ;_ end of lambda ) ;_ end of function ((lambda (/ res) (foreach item (mapcar (function (lambda (x) (vla-get-name (vlax-ename->vla-object x) ) ;_ end of vla-get-name ) ;_ end of lambda ) ;_ end of function ((lambda (/ item) (repeat (setq tab nil item (sslength selset) ) ;_ end setq (setq tab (cons (ssname selset (setq item (1- item)) ) ;_ end of ssname tab ) ;_ end of cons ) ;_ end of setq ) ;_ end of repeat tab ) ;_ end of lambda ) ) ;_ end of mapcar (if (not (member item res)) (setq res (cons item res)) ) ;_ end of if ) ;_ end of foreach (reverse res) ) ;_ end of lambda ) ) ;_ end of mapcar (vlax-for ent blk_def (vla-put-layer ent "A-EQUIP") (vla-put-color ent 121) (vla-put-lineweight ent aclnwtbyblock) (vla-put-linetype ent "byblock") ) ;_ end of vlax-for ) ;_ end of foreach (func_restore-layers) (vla-regen adoc acallviewports) ) ;_ end of progn ) ;_ end of if (vla-endundomark adoc) (foreach bl tab (vla-put-layer (vlax-ename->vla-object bl) "0") ;;; => Change "0" to desired Layer name ;;; ) (princ) ) ;_ end of defun Edited March 19, 2014 by srinak47 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.