jyan2000 Posted June 5, 2017 Posted June 5, 2017 Is there any lisp to move selected objects to new layer? I found this code (below) works well.. However inside blocks dont chage. (defun c:nl ( / ss layer) (and (princ "\nSelect objects to change to new layer: ") (setq ss (ssget)) (setq layer (getstring "\nNew layer name: ")) (or (snvalid layer) (prompt "\nInvalid layer name.") ) (vl-cmdf "_.-layer" "_M" layer "") (vl-cmdf "_.chprop" ss "" "_La" layer "") (setvar "clayer" "0") ) (princ) ) Quote
Jef! Posted June 5, 2017 Posted June 5, 2017 Hi jyan, welcome to cadtutor.net I don't know if it exists, but I modified your provided routine to achieve the desired result (defun c:nl (/ ss layer cnt en) (vl-load-com) (and (princ "\nSelect objects to change to new layer: ") (setq ss (ssget)) (setq layer (getstring "\nNew layer name: ")) (or (snvalid layer) (prompt "\nInvalid layer name.") ) (vl-cmdf "_.-layer" "_M" layer "") (vl-cmdf "_.chprop" ss "" "_La" layer "") (setvar "clayer" "0") ) ;part added by Jef! on june 05 2017 ;inspired by Peter Jamtgaard FIXBLKS. Put into lambdas with Cwake's help. (setq cnt (sslength ss)) (while (setq en (ssname ss (setq cnt (1- cnt)))) (if (= "INSERT" (cdr (assoc 0 (entget en)))) ((lambda (en / elst bnam flst) (setq elst (entget en) bnam (cdr (assoc 2 elst)) flst nil ) ((lambda (func) (func bnam) ) (lambda (bnam / benam) (if (not (member bnam flst)) (progn (setq flst (cons bnam flst) benam (tblobjname "block" bnam) ) (while (setq benam (entnext benam)) (if (= (cdr (assoc 0 (entget benam))) "INSERT") (func (cdr (assoc 2 (entget benam)))) (vla-put-layer (vlax-ename->vla-object benam) layer ) ) ) ) ) ) ) ) en ) ) (princ) ) ) Cheers! Quote
jyan2000 Posted June 6, 2017 Author Posted June 6, 2017 Hi Jef! That's fantastic. I've been searching for this code for months. You r brilliant. Thank you very much. Best Regards Jyan Quote
SLW210 Posted June 6, 2017 Posted June 6, 2017 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote
Jef! Posted June 6, 2017 Posted June 6, 2017 Hi Jef! That's fantastic. I've been searching for this code for months. You r brilliant. Thank you very much. Best Regards Jyan I'M glad I could help you out. You are welcome... and don't forget the code tags, it makes Hulk go green 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.