Jump to content

Layer Explode


mrjagsr744

Recommended Posts

For years I have been using the following LISP file to Explode blocks into the layer the were inserted on, but now that I am using AutoCAD 2008, I get the following message "nil

LEXPLODE

 

Select block reference, polyline, dimension, or mesh:

 

*Invalid selection*

Expects a point or

Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/P

revious/Undo/AUto/SIngle"

 

And, if I select the same item again it explodes into the layer it was created on.

I am attaching the LISP file.

Any ideas?

BTW, I am running AutoCAD 2008 with windows XP X64.

LEXPLODE.LSP

Link to comment
Share on other sites

It works on my PC, maybe some x64 AutoCAD bug? Try my just written code, it should work also as yours.

 

(defun c:lxplode(/ cSel cEnt oArr cLay)
 (vl-load-com)
 (if(setq cSel(entsel "\nSelect entity to explode: "))
   (progn
     (setq cEnt(vlax-ename->vla-object(car cSel)))
     (if(vl-catch-all-error-p
   (setq oArr(vl-catch-all-apply 'vla-Explode(list cEnt))))
(princ "\n<!> Can't explode this entity <!> ")
(progn
  (setq cLay(vla-get-Layer cEnt))
  (foreach e(vlax-safearray->list(vlax-variant-value oArr))
    (vla-put-Layer e cLay)
    ); end foreach
  (princ (strcat "\nEntities exploded onto layer " cLay "."))
  ); end progn
); end if
     ); end progn
   ); end if
 (princ)
 ); end of c:lxplode

Link to comment
Share on other sites

Thanks, your code works.

I think I must have changed something on my system variables because the same LISP that does not work on my machine, it works on the other X64 machines.

I will keep using your code.

Thanks again.

Link to comment
Share on other sites

Excuse me. More three lines of code:

 

(defun c:lxplode(/ cSel cEnt oArr cLay)
 (vl-load-com)
 (if(setq cSel(entsel "\nSelect entity to explode: "))
   (progn
     (setq cEnt(vlax-ename->vla-object(car cSel)))
     (if(vl-catch-all-error-p
   (setq oArr(vl-catch-all-apply 'vla-Explode
	       (list cEnt))))
(princ "\n<!> Can't explode this entity <!> ")
(progn
  (setq cLay(vla-get-Layer cEnt))
  (foreach e(vlax-safearray->list(vlax-variant-value oArr))
    (vla-put-Layer e cLay)
    [color="SeaGreen"](vla-put-Linetype e "ByLayer")[/color]
    [color="#2e8b57"](vla-put-Lineweight e acLnWtByLayer)[/color]
    ); end foreach
  [color="#2e8b57"](vla-Delete cEnt)[/color]
  (princ (strcat "\nEntities exploded onto layer " cLay "."))
  ); end progn
); end if
     ); end progn
   ); end if
 (princ)
 ); end of c:lxplode

Link to comment
Share on other sites

ASMI, after seeing quite a few of your routines - you seem to use only Visual LISP, instead of the older style using DXF tables and whatnot. - When I was looking to approach this problem, I considered using a selection set and then going through each element individually as if it had been selected using entsel.

 

Could this same routine be accomplished without the use of Visual LISP?

 

I must admit, I try to avoid Visual LISP at all costs - I know it can accomplish tasks much easier - but I find the functions so complicated to get my head around - I suppose its just what you're used to. :)

Link to comment
Share on other sites

ASMI, after seeing quite a few of your routines - you seem to use only Visual LISP, instead of the older style using DXF tables and whatnot. - When I was looking to approach this problem, I considered using a selection set and then going through each element individually as if it had been selected using entsel.

 

Could this same routine be accomplished without the use of Visual LISP?

 

In most cases use Visual LISP more convenient seems to me, but I can use and DXF codes. Here an example of this program without Visual LISP:

 

(defun c:lxplode2(/ cSel eEnt cLay lEnt cDxf nDxf)
 (if(setq cSel(entsel "\nSelect entity to explode: "))
   (progn
     (setq eEnt(car cSel)
    cLay(cdr(assoc 8(entget eEnt)))
    lEnt(entlast)); end setq
     (if(and
   (vl-cmdf "_.explode" eEnt)
   (not(equal lEnt(entlast)))
   ); end and
(progn
         (while(setq lEnt(entnext lEnt))
  (setq cDxf(entget lEnt)
	nDxf(subst(cons 8 cLay)(assoc 8 cDxf)cDxf))
    (entmod nDxf)
   ); end while
  (princ (strcat "\nEntities exploded onto layer " cLay "."))
  ); end progn
(princ "\n<!> Can't explode this entity <!> ")
); end if
     ); end progn
   ); end if
 (princ)
 ); end of c:lxplode2

 

I must admit, I try to avoid Visual LISP at all costs - I know it can accomplish tasks much easier - but I find the functions so complicated to get my head around - I suppose its just what you're used to.

 

I think that studying Visual LISP for you only a matter of time. To tell the truth it is very good that you at first study usual AutoLISP because it base knowledge, without which Visual LISP will not give to you big advantage.

Link to comment
Share on other sites

Thanks for your advice ASMI - much appreciated.

 

I understand the majority of your posted routine, except one thing:

 

Why must you include this line:

 

(not(equal lEnt(entlast)))

Link to comment
Share on other sites

Also, as a side note - would this work?

 

; Lxplode by ASMI - modified slightly (and hopefully correctly) by Lee McDonnell

(defun c:lxplode2 (/ cSel eEnt cLay lEnt cDxf nDxf)
   (setq ss (ssget))
   (if    (/= (setq ssl (sslength ss)) nil)
   (progn
       (setq index 0)
       (repeat ssl
       (setq eEnt (ssname ss index)
             cLay (cdr (assoc 8 (entget eEnt)))
             lEnt (entlast)
       ) ; end setq
       (if (and
           (vl-cmdf "_.explode" eEnt)
           (not (equal lEnt (entlast)))
           ) ; end and
           (progn
           (while (setq lEnt (entnext lEnt))
               (setq cDxf (entget lEnt)
                 nDxf (subst (cons 8 cLay) (assoc 8 cDxf) cDxf)
               ) ;_  end setq
               (entmod nDxf)
           ) ; end while
           (princ (strcat "\nEntities exploded onto layer " cLay "."))
           ) ; end progn
           (princ "\n<!> Can't explode this entity <!> ")
       ) ; end if
       (setq index (1+ index))
       ) ;_  end repeat
   ) ;_  end progn
   (princ "\nNo Entities Selected!")
   ) ;_  end if
   (princ)
) ; end of c:lxplode2

Link to comment
Share on other sites

Thanks for your advice ASMI - much appreciated.

 

I understand the majority of your posted routine, except one thing:

 

Why must you include this line:

 

(not(equal lEnt(entlast)))

 

Because if (equal lEnt(entlast)) last entity after explosion the same as before explosion, i.e. some reason explosion does not happen.

 

Also, as a side note - would this work?

 

It seems ok. But ss1 and index variables need to make local.

Link to comment
Share on other sites

It seems ok. But ss1 and index variables need to make local.

Ahh yes, I forgot oops :oops:

 

 

 

Because if (equal lEnt(entlast)) last entity after explosion the same as before explosion, i.e. some reason explosion does not happen.

 

I thought that entlast was the last entity "created" - so the last entity created may not necessarily be the entity that is going to be exploded...?

Link to comment
Share on other sites

Ok, with variables localised:

 

; Lxplode by ASMI - modified slightly (and hopefully correctly) by Lee McDonnell

(defun c:lxplode2 (/ ss ssl index eEnt cLay lEnt cDxf nDxf)
   (setq ss (ssget))
   (if    (/= (setq ssl (sslength ss)) nil)
   (progn
       (setq index 0)
       (repeat ssl
       (setq eEnt (ssname ss index)
             cLay (cdr (assoc 8 (entget eEnt)))
             lEnt (entlast)
       ) ; end setq
       (if (and
           (vl-cmdf "_.explode" eEnt)
           (not (equal lEnt (entlast)))
           ) ; end and
           (progn
           (while (setq lEnt (entnext lEnt))
               (setq cDxf (entget lEnt)
                 nDxf (subst (cons 8 cLay) (assoc 8 cDxf) cDxf)
               ) ;_  end setq
               (entmod nDxf)
           ) ; end while
           (princ (strcat "\nEntities exploded onto layer " cLay "."))
           ) ; end progn
           (princ "\n<!> Can't explode this entity <!> ")
       ) ; end if
       (setq index (1+ index))
       ) ;_  end repeat
   ) ;_  end progn
   (princ "\nNo Entities Selected!")
   ) ;_  end if
   (princ)
) ; end of c:lxplode2

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