Darrell Posted August 8, 2024 Posted August 8, 2024 I need a lisp that will find blocks of a specific name in a drawing and move them all to a certain layer. Quote
ronjonp Posted August 8, 2024 Posted August 8, 2024 Give this a try, assuming they are not modified dynamic blocks. (defun c:foo (/ s) (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "YOURBLOCKNAME")))) (foreach e (mapcar 'cadr (ssnamex s)) (entmod (append (entget e) '((8 . "YOURLAYERNAME"))))) ) (princ) ) 1 Quote
Darrell Posted August 8, 2024 Author Posted August 8, 2024 49 minutes ago, ronjonp said: Give this a try, assuming they are not modified dynamic blocks. (defun c:foo (/ s) (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "YOURBLOCKNAME")))) (foreach e (mapcar 'cadr (ssnamex s)) (entmod (append (entget e) '((8 . "YOURLAYERNAME"))))) ) (princ) ) Thanks I'll give it a try! Quote
BIGAL Posted August 9, 2024 Posted August 9, 2024 (edited) Hope you don't mind @ronjonp just added get name and layer by object. (defun c:foo2 ( / s bname) (setq bname (cdr (assoc 2 (entget (car (entsel "\nPlease pick block for name search ")))))) (setq lay (cdr (assoc 8 (entget (car (entsel "\nPlease pick any object for destination layer ")))))) (if (setq s (ssget "_X" (list (cons 0 "INSERT") (cons 2 bname)))) (foreach e (mapcar 'cadr (ssnamex s)) (entmod (append (entget e) (list (cons 8 lay))))) ) (princ) ) Can also use CHPROP on selection set s, I think the foreach may be faster though. Edited August 9, 2024 by BIGAL 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.