Jump to content

Recommended Posts

Posted

Hello, everybody,
I have a lot of blocks in my drawing with nested blocks that are in the same layer as the block. In certain cases I need to freeze the nested blocks, and therefore I would need to change the layer of the nested blocks. I need to change the nested blocks whose name contains a specific string. I need this either for selected blocks or all blocks in the drawing. I would be grateful for help as my attempts have been unsuccessful.

Posted

Try something like this - change the value of the two variables at the top of the code to suit:

(defun c:test ( / bln idx lst nla pat )
    (setq pat "*block*"
          nla "NewLayer"
          pat (strcase pat)
    )
    (if (setq sel (ssget '((0 . "INSERT"))))
        (repeat (setq idx (sslength sel))
            (setq idx (1- idx)
                  bln (cdr (assoc 2 (entget (ssname sel idx))))
            )
            (if (not (member bln lst))
                (progn
                    (setq lst (cons bln lst))
                    (processblock bln pat nla)
                )
            )
        )
    )
    (princ)
)

(defun processblock ( bln str lay / ent )
    (if (setq ent (tblobjname "block" bln))
        (while (setq ent (entnext ent))
            (processobject ent str lay)
        )
    )
)

(defun processobject ( ent str lay / bln enx )
    (cond
        (   (not (setq enx (entget ent))))
        (   (/= "INSERT" (cdr (assoc 0 enx))))
        (   (not (wcmatch (setq bln (strcase (cdr (assoc 2 enx)))) str))
            (processblock bln str lay)
        )
        (   (entmod (subst (cons 8 lay) (assoc 8 enx) enx))
            (processblock bln str lay)
        )
    )
)

(princ)

 

  • Like 1
  • Thanks 4
Posted

as always you make it look so easy master Lee 🤓

  • Like 2
Posted

Perfect as always. Thank you very much.

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