samarth yadav Posted October 23 Posted October 23 i have a autocad lisp https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-block-entities-from-layer-zero-to-current/td-p/11584200 from this forum this lisp work fine but can anyone change it to do multiple blocks. the lisp basically does that it changes block object inside layer to current layer i want same process but for multiple blocks anyhelp would be appreciated. thanks.https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-block-entities-from-layer-zero-to-current/td-p/11584200 (defun c:fb (/ block bname) (setq block (ssget "_+.:E:S" '((0 . "INSERT")))) ;; select single entity, for multiple selection its too slow anyway (setq currentlayer (getvar "clayer")) (setq bname (cdr (assoc 2 (entget(ssname block 0))))) ;; index forgotten , 0 is the first (command "-bedit" bname ) (command "change" "all" "" "p" "la" currentlayer "") ; (command "setbylayer" "all" "" "yes" "yes") (command "_.bclose" "_save") ;; close the editor (princ) ) (vl-load-com) (prompt "\nType FB to set all entities in a block to the current layer.") Quote
Steven P Posted October 23 Posted October 23 (edited) See this which is the basis for the change you want to make: https://lee-mac.com/ssget.html Try this untested change, however since you are editing each block in turn in the block editor it could be slow EDITED CODE: Missed a ')' (defun c:fb (/ block bname acount) (setq block (ssget '((0 . "INSERT")))) ;; select single entity, for multiple selection its too slow anyway ;; CHANGED THIS LINE (setq currentlayer (getvar "clayer")) (setq acount 0) ;;ADDED THIS LINE (while (< acount (sslength block)) ;; ADDED THIS LINE (setq bname (cdr (assoc 2 (entget(ssname block acount))))) ;; index forgotten , 0 is the first;; CHANGED THIS LINE (command "-bedit" bname ) (command "change" "all" "" "p" "la" currentlayer "") ; (command "setbylayer" "all" "" "yes" "yes") (command "_.bclose" "_save") ;; close the editor (setq acount (+ acount 1)) ;; ADDED THIS LINE ) ; end while ;; ADDED THIS LINE (princ) ) (vl-load-com) (prompt "\nType FB to set all entities in a block to the current layer.") Edited October 25 by Steven P 1 Quote
samarth yadav Posted October 25 Author Posted October 25 (edited) Edited October 25 by samarth yadav Quote
samarth yadav Posted October 25 Author Posted October 25 On 10/23/2024 at 6:12 PM, Steven P said: See this which is the basis for the change you want to make: https://lee-mac.com/ssget.html Try this untested change, however since you are editing each block in turn in the block editor it could be slow (defun c:fb (/ block bname acount) (setq block (ssget '((0 . "INSERT")))) ;; select single entity, for multiple selection its too slow anyway ;; CHANGED THIS LINE (setq currentlayer (getvar "clayer")) (setq acount 0) ;;ADDED THIS LINE (while (< acount (sslength block) ;; ADDED THIS LINE (setq bname (cdr (assoc 2 (entget(ssname block acount))))) ;; index forgotten , 0 is the first;; CHANGED THIS LINE (command "-bedit" bname ) (command "change" "all" "" "p" "la" currentlayer "") ; (command "setbylayer" "all" "" "yes" "yes") (command "_.bclose" "_save") ;; close the editor (setq acount (+ acount 1)) ;; ADDED THIS LINE ) ; end while ;; ADDED THIS LINE (princ) ) (vl-load-com) (prompt "\nType FB to set all entities in a block to the current layer.") thanks for the response but not able to select more than one block at a time it is working same as before Quote
Steven P Posted October 25 Posted October 25 I missed a closing bracket - I've modified the code above and it should work now Quote
samarth yadav Posted October 25 Author Posted October 25 Thank you steven working perfectly fine thanks for the help you saved so much time 1 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.