Jump to content

Exploding ONLY nested blocks


ChristopherM

Recommended Posts

Hi

 

Tried to look for something like the topic says but only found topics that explodes everything. And I want to explode ONLY the blocks that are inside a block and then keeping the main block that is placed.

 

I have hundreds blocks and some of them are inside a block so something automatic would be nice :)

 

Thank for the help

CM

Link to comment
Share on other sites

 

Nice one, expected recursion :)

I had fun trying the iterative way:

 

(defun C:test ( / o n L b)
 
 (defun Bdef->SubentsL ( nm / e L )
   (setq e (cdr (assoc -2 (entget (tblobjname "BLOCK" nm)))))
   (while e (setq L (cons e L)) (setq e (entnext e))) L
 )
 
 (and 
   (setq n (car (entsel "\nSelect block to \"flatten\": ")))
   (setq n (vlax-ename->vla-object n))
   (setq n (vla-get-EffectiveName n))
   (progn 
     (while 
       (vl-some 
         (function
           (lambda (x / o) 
             (and 
               (= "INSERT" (cdr (assoc 0 x))) 
               (setq L (cons (cdr (assoc 2 x)) L))
               (setq o (vlax-ename->vla-object (cdr (assoc -1 x))))
               (vlax-write-enabled-p o)
               (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Explode (list o))))
               (not (vla-Delete o))
             )
           )
         )
         (mapcar 'entget (Bdef->SubentsL n))
       )
     ); while
     (and (= "Yes" (progn (initget "Yes No") (cond ((getkword "\nAttempt to purge the SubBlocks? [Yes/No] <Yes>: ")) ("Yes"))))
       (setq b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
       (foreach x L (vl-catch-all-apply 'vla-Delete (list (vla-item b x))) )
     ); and
   ); progn
 ); and
 
 (princ)
); defun

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