Jump to content

check block has layers including nested blocks.


Recommended Posts

Posted

Hi I tired to change block's layer to 0 if it has more than 2 layers (except layer 0, defpoints ) inside and also nested blocks.

 

So I made a lisp and but it doesn't including nested blocks. please help

 

ex)

1. block 1 has  block2, block3 and many layers entities (circle, lines...)

  -> block 1 layer to 0

 

2. block 2 has block 4 (layer A) and block 5 (layer B).

  -> block 2 layer to 0

 

3. block 3 has 1 layer entities.

  -> nil

 

<LISP>

(defun c:test ( / ss ent tblist ename llist blist )
  (setq ss (ssget "_All" '((0 . "INSERT"))))
  (setq i (sslength ss))
  
  (repeat (setq i (sslength ss))
    (setq ent (ssname ss (setq i (- i 1))))

    (if (= (cdr (assoc 0 (entget ent))) "INSERT")
      (progn
        (setq tblist (tblsearch "BLOCK" (cdr (assoc 2 (entget ent)))))
        (setq ename (cdr (assoc -2 tblist)))
        (while ename
          (if llist
            (setq llist (append (list (cdr (assoc 8 (entget ename)))) llist))
            (setq llist (list (cdr (assoc 8 (entget ename)))))
          )
          (if (= "INSERT" (cdr (assoc 0 (entget ename))))
            (progn
              (setq blist (append (list (cdr (assoc -1 (entget ename)))) blist))
              (setq blist (list (cdr (assoc -1 (entget ename)))))
              (setq tblist (tblsearch "BLOCK" (cdr (assoc 2 (entget ent)))))
            )
          )
          (princ (cdr (assoc 0 (entget ename))))
          ;(princ (car blist))
          (vla-put-layer (vlax-ename->vla-object (car blist)) "0")
          
          (setq ename (entnext ename))
        )

        (setq llist (vl-remove "0" llist))
        
        (if (<= 2 (length llist))
          (progn
            (vla-put-layer (vlax-ename->vla-object ent) "0")
          )
        )
      )
    )
  )
  
  (princ)
)

Posted

This uses the block definition to update the blocks in the drawing.

 

(defun C:FOO (/ blk Drawing blkname ent x)
  (vl-load-com)
  (vlax-for blk (vla-get-blocks (setq Drawing (vla-get-activedocument (vlax-get-acad-object))))
    (if (and (= (vla-get-isxref blk) :VLAX-FALSE)
             (not (wcmatch (vla-get-name blk) "*`**,*|*"))
        )
      (progn
        (setq blkname (vla-get-name blk))
        (setq ent (tblobjname "BLOCK" blkname))
        (while (setq ent (entnext ent))
          (if (/= (cdr (assoc 8 (setq x (entget ent)))) "0")
            (entmod (subst (cons 8 "0") (assoc 8 x) x))
          )
        )
      )
    )
  )
  (vla-Regen Drawing)
  (princ)
)

 

 

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