Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

EXPLODE TEXT -

9 REPLIES 9
Reply
Message 1 of 10
allanbsteven
1274 Views, 9 Replies

EXPLODE TEXT -

Is it possible to use the explode command in a lisp. My issue is that we export CIVIL3d to Autocad and we have to explode the spot labels twice to have them go from a block reference to Mtext then finally to text. It would be great to add this to a routine I have in the tool palette.

Thanks

Allan

9 REPLIES 9
Message 2 of 10
hmsilva
in reply to: allanbsteven

Something like this perhaps.

(defun c:test (/ ENT HND I OBJ SS SS1)
  (setq ss (ssadd))
  (setq obj (entlast))
  (if (setq ss1 (ssget "_+.:E:S:L" '((0 . "INSERT"))))
    (progn
      (command "_.explode" ss1)
      (while (setq obj (entnext obj))
	(ssadd obj ss)
      )
      (repeat (setq i (sslength ss))
	(setq hnd (ssname ss (setq i (1- i)))
	      ent (entget hnd)
	)
	(if (= (cdr (assoc 0 ent)) "MTEXT")
	  (command "_.explode" hnd)
	)
      )
    )
  )
  (princ)
)

HTH

Henrique

EESignature

Message 3 of 10
Lee_Mac
in reply to: allanbsteven

Try the following function:

 

(defun explode-to-end ( ent / enl tmp )
    (setq enl (entlast))
    (while (setq tmp (entnext enl)) (setq enl tmp))
    (explode ent)
    (while (setq enl (entnext enl)) (explode-to-end enl))
    (princ)
)

(defun explode ( ent / cmd rtn qaf )
    (if
        (not
            (member (cdr (assoc 0 (entget ent)))
               '(
                    "ARC"
                    "ATTDEF"
                    "CIRCLE"
                    "ELLIPSE"
                    "LINE"
                    "POINT"
                    "RAY"
                    "SPLINE"
                    "TEXT"
                    "XLINE"
                )
            )
        )
        (progn
            (setq qaf (getvar 'qaflags)
                  cmd (getvar 'cmdecho)
            )
            (setvar 'qaflags 1)
            (setvar 'cmdecho 0)
            (setq rtn (vl-cmdf "_.explode" ent ""))
            (setvar 'cmdecho cmd)
            (setvar 'qaflags qaf)
            rtn
        )
    )
)

 

Call the function with the entity name of the object to be exploded, e.g.:

 

(defun c:test ( / ent )
    (if (setq ent (car (entsel)))
        (explode-to-end ent)
    )
    (princ)
)

 

Message 4 of 10
allanbsteven
in reply to: hmsilva

Thanksyou but it will only work for me on a single entity, can it be done to multiple?

Thanks

Allan

Message 5 of 10
allanbsteven
in reply to: hmsilva

Hi There, can this be done to multiple text elements? Currently I can only do one at a time with this lisp?
Thanks
Message 6 of 10

To do multiple text elements change the currest test function to this function from Lee Mac's site

and change (print x) to (explode-to-end e)

 

(defun c:test1 ( / e i n s x )
    (if (setq s (ssget))
        (progn
            (setq i 0
                  n (sslength s)
            )
            (while (< i n)
                (setq e (ssname s i)
                      x (cdr (assoc 0 (entget e)))
                      i (1+ i)
                )
                (explode-to-end e)
            )
        )
    )
    (princ)
)

 

Message 7 of 10

Thanks for the reply, I am new to lsip so bear with me.

I tried to rearrange this but I still cant get it to work?

Any help is appreciated, thakyou all for your time in the mean time.

Cheers

Allan

Message 8 of 10

(defun explode-to-end ( ent / enl tmp )
    (setq enl (entlast))
    (while (setq tmp (entnext enl)) (setq enl tmp))
    (explode ent)
    (while (setq enl (entnext enl)) (explode-to-end enl))
    (princ)
)

(defun explode ( ent / cmd rtn qaf )
    (if
        (not
            (member (cdr (assoc 0 (entget ent)))
               '(
                    "ARC"
                    "ATTDEF"
                    "CIRCLE"
                    "ELLIPSE"
                    "LINE"
                    "POINT"
                    "RAY"
                    "SPLINE"
                    "TEXT"
                    "XLINE"
                )
            )
        )
        (progn
            (setq qaf (getvar 'qaflags)
                  cmd (getvar 'cmdecho)
            )
            (setvar 'qaflags 1)
            (setvar 'cmdecho 0)
            (setq rtn (vl-cmdf "_.explode" ent ""))
            (setvar 'cmdecho cmd)
            (setvar 'qaflags qaf)
            rtn
        )
    )
)

(defun c:test ( / e i n s x )
    (if (setq s (ssget))
        (progn
            (setq i 0
                  n (sslength s)
            )
            (while (< i n)
                (setq e (ssname s i)
                      x (entget e)
                      i (1+ i)
                )
        (explode-to-end e)
            )
        )
    )
    (princ)
)

 

Download the attached lisp file.

 Command name : TEST

 

How to Run an AutoLISP Program

Message 9 of 10

Thanks a million, works a treat.

 

Message 10 of 10
Lee_Mac
in reply to: allanbsteven

Excellent to hear allanbsteven Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost