Jump to content

Lisp to move specific blocks, by name, to a certain layer


Darrell

Recommended Posts

I need a lisp that will find blocks of a specific name in a drawing and move them all to a certain layer.

Link to comment
Share on other sites

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)
)

 

  • Agree 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 by BIGAL
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...