Recursive Explode lisp

Recursive Explode lisp

Anonymous
Not applicable
1,368 Views
4 Replies
Message 1 of 5

Recursive Explode lisp

Anonymous
Not applicable

Hello all, I'm new here so please correct me If i am not following any rules.

 

I'm trying to write/ manipulate some lisp code that will continue to explode blocks until no more can be exploded. 

I've managed to get this to happen, but the lisp function keeps running even though the returned results are unchanging.

eg. This is continuously returned. 

"Command: _.explode
Select objects: 7 found
Select objects:
Cannot explode that block.
Cannot explode that block.
Cannot explode that block.
Cannot explode that block.
Cannot explode that block.
Cannot explode that block.
Cannot explode that block.

 

I believe I need to find a way to tell the lisp to stop once it returns two unchanged numbers of found blocks (in the case above - 7).

If anyone is able to help I would really appreciate it. Code below:

 

(defun c:exall(/ bSet)
(setvar "qaflags" 1)
(while (setq bSet(ssget "_X" '((0 . "INSERT"))))
(command "_.explode" bSet "")
); end while
(repeat 3(command "-purge" "all" "" "n"))
(setvar "qaflags" 0)
(princ)
); end of c:exall

0 Likes
Accepted solutions (1)
1,369 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant
This looks like nice complex routine for your issue...
https://sites.google.com/site/cadkits/home/explodeall
0 Likes
Message 3 of 5

Anonymous
Not applicable

Ha, thank you BeeKeeCZ.

 

I actually want to add it to a much larger routine which I can batch apply to files. 

Any other ideas?

0 Likes
Message 5 of 5

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

...

I'm trying to write/ manipulate some lisp code that will continue to explode blocks until no more can be exploded. 

...


Something like this, perhaps

 

(vl-load-com)
(defun c:demo (/ explodable adoc exp_lst not_explodable ss)

  (defun explodable (ss / i lst name obj)
    (repeat (setq i (sslength ss))
      (setq obj  (vlax-ename->vla-object (ssname ss (setq i (1- i))))
            name (vla-get-effectivename obj)
      )
      (if (and (not (vl-position name not_explodable))
               (vlax-write-enabled-p obj)
          )
        (setq lst (cons obj lst))
      )
    )
    lst
  )

  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark adoc)
  (vlax-for blk (vla-get-Blocks adoc)
    (if (or (eq (vla-get-explodable blk) :vlax-false)
            (eq (vla-get-isxref blk) :vlax-true)
        )
      (setq not_explodable (cons (vla-get-name blk) not_explodable))
    )
  )
  (while (and (setq ss (ssget "_X" '((0 . "INSERT"))))
              (setq exp_lst (explodable ss))
         )
    (foreach blk exp_lst
      (vla-explode blk)
      (vla-delete blk)
    )
  )
  (vla-endundomark adoc)
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature