MTEXT EXPLODE LISP KEEPS CHANGING MY QAFLAGS TO 1

MTEXT EXPLODE LISP KEEPS CHANGING MY QAFLAGS TO 1

Anonymous
Not applicable
1,103 Views
5 Replies
Message 1 of 6

MTEXT EXPLODE LISP KEEPS CHANGING MY QAFLAGS TO 1

Anonymous
Not applicable

Hi again family, im using a lisp to help get rid of all my mtext that is left in a drawing. The issue im having is that it sets my QAFLAGS to 1 and that really messes with the way i draft and also messes with some other routines we have. is there a way to add something to this lisp that would help avoid this? the way it reads below should avoid this from happening but its still happening and i cant figure it out. please help because i think its also random. sometimes it feels like a nut and sometimes it dont. see attached for mtext leader we use

 

(defun c:xmt (/ myss)
(setq myss (ssget "X" '((0 . "MTEXT"))))
(setvar "qaflags" 1)
(command "EXPLODE" myss "")
(setvar "qaflags" 0)
(princ)
)
0 Likes
Accepted solutions (1)
1,104 Views
5 Replies
Replies (5)
Message 2 of 6

dlanorh
Advisor
Advisor

Your lisp is re-setting qaflags to 0 after exploding the selection set. You cannot explode the selection set unless qaflags is 1. A probable cause could be an error in exploding an object e.g. something on a locked layer, since ssget "X" selects objects on locked layers and the lisp is exiting without resetting qaflags

 

Solutions :

 

1. a local *error* to capture and reset qaflags.

2. explode each item in the selection set individually checking if it is on a locked layer (don't need to use qaflags)

 

I am not one of the robots you're looking for

Message 3 of 6

Anonymous
Not applicable

i want to be completely honest with you...my head exploded trying to figure out what you mean lol

 

if i understand...i should explode my mleader text first then us the mtext explode lisp?

something like this? 

 

(defun c:xml ( / *error* ss vl ov )

(defun *error* ( msg )
(and ov (mapcar 'setvar vl ov))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)
)

(setq vl '("CTAB" "CMDECHO" "QAFLAGS") ov (mapcar 'getvar vl))
(mapcar 'setvar (cdr vl) '(0 5))

(foreach x (cons "Model" (layoutlist))
(setvar 'ctab x)
(if (setq ss (ssget "_X" (list '(0 . "MULTILEADER") (cons 410 x))))
(command "_.explode" ss "")
)
)

(mapcar 'setvar vl ov)
(princ)
)

0 Likes
Message 4 of 6

dlanorh
Advisor
Advisor
Accepted solution

@Anonymous wrote:

i want to be completely honest with you...my head exploded trying to figure out what you mean lol

 

if i understand...i should explode my mleader text first then us the mtext explode lisp?

something like this? 

 

(defun c:xml ( / *error* ss vl ov )

(defun *error* ( msg )
(and ov (mapcar 'setvar vl ov))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)
)

(setq vl '("CTAB" "CMDECHO" "QAFLAGS") ov (mapcar 'getvar vl))
(mapcar 'setvar (cdr vl) '(0 5))

(foreach x (cons "Model" (layoutlist))
(setvar 'ctab x)
(if (setq ss (ssget "_X" (list '(0 . "MULTILEADER") (cons 410 x))))
(command "_.explode" ss "")
)
)

(mapcar 'setvar vl ov)
(princ)
)


Pretty much spot on 😁  But it looks like you are setting qaflags to 5?

 

I personally would change it slightly to

 

(defun c:xml ( / *error* ss vl ov )

  (defun *error* ( msg )
    (mapcar 'setvar vl ov)
    (if (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))
    (if (not (zerop (getvar "QAFLAGS"))) (alert (strcat "\nQAFLAGS = " (itoa (getvar "QAFLAGS")))))
    (princ)
  )

  (setq vl '("CMDECHO" "QAFLAGS" "CTAB") ov (mapcar 'getvar vl))
  (mapcar 'setvar vl '(0 1))

  (foreach x (cons "Model" (layoutlist))
    (setvar 'ctab x)
    (setq ss (ssget "_X" (list '(0 . "MULTILEADER") (cons 410 x))))
    (command "_.explode" ss "")
    (setq ss nil)
  )

  (mapcar 'setvar vl ov)
  (if (not (zerop (getvar "QAFLAGS"))) (alert (strcat "\nQAFLAGS = " (itoa (getvar "QAFLAGS")))))
  (princ)
)

 

QAFLAGS is an undocumented system variable which can cause various problems as you know, so if you exit via the local *error* or normally let the user know if it is not zero.

 

If you are trying to explode ALL your MLEADERS and ALL your MTEXT, you could combine the two together.

 

(defun c:xml ( / *error* vl ov ss ss1 )

  (defun *error* ( msg )
    (mapcar 'setvar vl ov)
    (if (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))
    (if (not (zerop (getvar "QAFLAGS"))) (alert (strcat "\nQAFLAGS = " (itoa (getvar "QAFLAGS")))))
    (princ)
  )

  (setq vl '("CMDECHO" "QAFLAGS" "CTAB") ov (mapcar 'getvar vl))
  (mapcar 'setvar vl '(0 1))

  (foreach x (cons "Model" (layoutlist))
    (setvar 'ctab x)
    (setq ss (ssget "_X" (list '(0 . "MULTILEADER") (cons 410 x))))
    (command "_.explode" ss "")
    (setq ss1 (ssget "_X" (list '(0 . "MTEXT") (cons 410 x))))
    (command "_.explode" ss1 "")
    (setq ss nil ss1 nil)
  )

  (mapcar 'setvar vl ov)
  (if (not (zerop (getvar "QAFLAGS"))) (alert (strcat "\nQAFLAGS = " (itoa (getvar "QAFLAGS")))))
  (princ)
)

 

 

I am not one of the robots you're looking for

Message 5 of 6

cadffm
Consultant
Consultant

By using native commands (like explode) you have to make sure the the selection set is valid for the command.

 

Means  one or more objects are on unlocked layers.

 

And another thing:

"You cannot explode the selection set unless qaflags is 1."

Thats not right, the current cersion of explode accepts multiple objects, so you don't need the qaflags handling, you can also use the current version of the explode command.

 

(progn(initcommandversion)(command "_.explode" ss ""))

 

 

Sebastian

Message 6 of 6

Anonymous
Not applicable

works perfect! thank you for the help 🙂

0 Likes