Lisp to explode all blocks in model space.

Lisp to explode all blocks in model space.

MSA3DY
Contributor Contributor
5,217 Views
21 Replies
Message 1 of 22

Lisp to explode all blocks in model space.

MSA3DY
Contributor
Contributor

Hi for all.

May you help me in a lisp that explode all blocks in model space only.

I got a lisp from forum before but it exploded all blocks in model and paper space and I had a problem blocks with attributes are exploded as well.

0 Likes
5,218 Views
21 Replies
Replies (21)
Message 2 of 22

davinatkins
Advocate
Advocate

I don't have a lisp for that, but you can do the same thing with quickselect.

 

Start the quickselect command and search for entity type "blocks". Generally, filtering by color = bylayer will grab every block.

 

Click ok, and then click explode.

0 Likes
Message 3 of 22

MSA3DY
Contributor
Contributor
I already do this. but need to save steps. because I make tons of changes in one day.
0 Likes
Message 4 of 22

devitg
Advisor
Advisor

@MSA3DY please upload your lsp and dwg .

 

 

0 Likes
Message 5 of 22

ronjonp
Advisor
Advisor
0 Likes
Message 6 of 22

Kent1Cooper
Consultant
Consultant

@MSA3DY wrote:

....

I got a lisp from forum before but it exploded all blocks in model and paper space and I had a problem blocks with attributes are exploded as well.


Presumably your AutoLisp routine includes something like this to find all Blocks:

 

(ssget "_X" '((0 . "INSERT")))

 

You can filter the selection to find only those in Model Space:

(ssget "_X" '((0 . "INSERT") (410 . "Model")))

 

and assuming the problem with Blocks with attributes is that you don't want them Exploded at all [i.e. not BURST to explode the Block parts but keep the Attribute values], you can filter for only those in Model Space without Attributes:

(ssget "_X" '((0 . "INSERT") (410 . "Model") (66 . 0)))

Kent Cooper, AIA
0 Likes
Message 7 of 22

paullimapa
Mentor
Mentor

try attached modified version


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 22

jtohill
Advocate
Advocate

Interested in knowing why someone would want to do what you are looking to do. I am looking for how to remove explode.

0 Likes
Message 9 of 22

Moshe-A
Mentor
Mentor

@jtohill ,

 


@jtohill wrote:

Interested in knowing why someone would want to do what you are looking to do. I am looking for how to remove explode.


there is an UNDEFINE & REDEFINE commands for that purpose.

generally users seeks for exploding xrefs, blocks, attribute blocks even polylines cause they lack of knowlege how to modify them - c'est la vie 😀

 

 

 

0 Likes
Message 10 of 22

Sea-Haven
Mentor
Mentor

Bricscad has a remake a block looking at matching objects, replacing with blocks. Trying to remember command.

0 Likes
Message 11 of 22

ronjonp
Advisor
Advisor

@Sea-Haven wrote:

Bricscad has a remake a block looking at matching objects, replacing with blocks. Trying to remember command.


It's called 'blockify'.

0 Likes
Message 12 of 22

MSA3DY
Contributor
Contributor
it's easy, blocks prevent me from making stretch command , sometimes I have to change the entire 2 elevations with plan in one step by stretch command. in this state if the blocks are existed I have to change each block by block editor or refedit.
0 Likes
Message 13 of 22

Sea-Haven
Mentor
Mentor

Thanks ronjonp, have not needed to use it very rare to explode lots of blocks.

0 Likes
Message 14 of 22

MSA3DY
Contributor
Contributor
(ssget "_X" '((0 . "INSERT"))) , this code is great.
but I want to explode this selection
I made something like this but don't work.
(DEFUN C:xall ()
(ssget "_X" '((0 . "INSERT")))
(COMMAND "explode" "_X" ""))
0 Likes
Message 15 of 22

paullimapa
Mentor
Mentor

since you actually want to select objects then don't use (ssget "X")

also remember to precede the explode command with (initcommandversion) to force explode command to work on a selection set.

EXPLODES is a full blown block selection version checking also for selected objects on locked layers prior to executing explode....enjoy...

 

; ExplodeS function makes Explode command on multiple objects possible when
; Explode command runs from lisp
; by using (initcommandversion) prior to the explode call
; as mentioned by BeekeeCZ (Mentor) Beekeeper CZ in
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/can-t-explode-multiple-items-with-script-file/m-p/11366987#M435204
(defun c:ExplodeS (/ ent cmdecho i IsLayerLocked lyrname menuecho ss) 
;;; IsLayerLocked
;;;  Returns T if Locked
;;;        nil if Unlocked or not found
;;;        nil if lname is not a string
;;; https://www.theswamp.org/index.php?topic=888.0
 (defun IsLayerLocked (lname / ent)
  (if (and (=(type lname) 'STR)(setq ent (tblobjname "LAYER" lname)))
      (= 4 (logand 4 (cdr (assoc 70 (entget ent)))))
  )
 ) ; end defun
  ; setup environment
  (setq 
    cmdecho(getvar"cmdecho")
    menuecho(getvar"menuecho")
  )
  (setvar"cmdecho"0)
  (setvar"menuecho"0)
  (if (setq ss (ssget '((0 . "INSERT")))) ; if insert blocks selected - note objects on locked layers not tested
    (progn 
      (repeat (setq i (sslength ss)) ; loop through process of checking for objects on locked layers
       (setq lyrname (cdr(assoc 8 (entget (setq ent (ssname ss (setq i (1- i))))))))
       (if (IsLayerLocked lyrname) 
        (progn
         (princ(strcat"\nBlock [" (cdr(assoc 2 (entget ent))) "] Found on Locked Layer [" lyrname "] is removed from selection."))
         (ssdel ent ss) ; remove ojbects on locked layers
        )  
       ) ; if layer is locked
      ) ; repeat
      (if (not(zerop(sslength ss))) ; test if there are objects left in selection
        (progn
         (initcommandversion) ; force explode to function with selection set
         (command "_.Explode" ss "")
        )
      ) ; if objects in selection
      (princ(strcat"\nTotal of [" (itoa (sslength ss)) "] Block Object(s) Successfully Exploded."))
    ) ; progn
    (progn 
      (princ"\nNo Block Object(s) Selected.")
    ) ; else
  ) ; if 
  ; restore environment
  (setvar"cmdecho"cmdecho)
  (setvar"menuecho"menuecho)
  (princ)
) ; defun

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 16 of 22

Kent1Cooper
Consultant
Consultant

@MSA3DY wrote:
(ssget "_X" '((0 . "INSERT"))) , this code is great.
but I want to explode this selection
I made something like this but don't work.
(DEFUN C:xall ()
(ssget "_X" '((0 . "INSERT")))
(COMMAND "explode" "_X" ""))

Your "_X" is a selection mode for use within (ssget), and not valid input for the object-selection in the Explode command.  Did you intend to put that selection into a variable?  That's an option, but not necessary -- you could do [in simplest terms to do what your code is apparently intended to do] this:

 

(defun C:XALL ()

  (initcommandversion); for following to Explode more than one

  (command "_.explode" (ssget "_X" '((0 . "INSERT"))) "")

)

 

But that doesn't limit itself to the current space in selection -- it will "find" all Blocks in other spaces, too, though it won't Explode them this way [if that's part of what you want to do], because commands involving object selection can "see" only objects in the same space, even though the (ssget) function can reach beyond that.  It could be made to get them all, by moving into each space in which such objects are found.

 

And it doesn't deal with the question of locked Layers.

Kent Cooper, AIA
0 Likes
Message 17 of 22

MSA3DY
Contributor
Contributor
Great thanks , It's working perfect.
0 Likes
Message 18 of 22

dean_witherden
Community Visitor
Community Visitor

Might be a bit late to the party here but will this work with blocks that are set to not be able to exploded in the block definition? I'm a surveyor and use this data to go into machine control systems  which can only handle polylines so need to explode. Don't know why these settings can't disable once the data is copied, I can't even access the setting in the block editor.

0 Likes
Message 19 of 22

ronjonp
Advisor
Advisor

@dean_witherden Run this first:

(defun c:foo nil
  (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (if	(= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))
      (vla-put-explodable b -1)
    )
  )
  (princ)
)
0 Likes
Message 20 of 22

dean_witherden
Community Visitor
Community Visitor

Thanks @ronjonp 

0 Likes