Purge DWG LISP

Purge DWG LISP

Anonymous
Not applicable
2,262 Views
4 Replies
Message 1 of 5

Purge DWG LISP

Anonymous
Not applicable

I have this routine for our draftsman, but giving error. Can any one let me know corrective action.

 

(defun c:compress()
 (vl-load-com)
 (setq fs1 (vl-file-size (getvar 'DWGNAME)))
 (setvar "filedia" 0)
 (setq ce (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (command "layer" "s" "0" "")
 (command "zoom"  "e")
 (repeat 3
  (command "._purge" "_A" "*" "_N")
  (command "purge" "regapps" "" "n")
 )
 (setvar "cmdecho" ce)
 (command "_qsave")
 (setvar "filedia" 1)
 (setq fs2 (vl-file-size (getvar 'DWGNAME)))
 (princ (strcat "\nFile Size before purging : " FS1))
 (princ (strcat "\nFile Size after purging : " FS2))
 (princ)
)

 

After adding red text it is giving below error.

Error: bad argument type: stringp nil

 

 

0 Likes
Accepted solutions (3)
2,263 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Accepted solution

FS1 & FS2 are integers and you can not string concatenate a string and a number).
Use ITOA to convert an integer to a string
Use RTOS to convert a real to a string
Change to -
(princ (strcat "\nFile Size before purging : " (itoa FS1)))
(princ (strcat "\nFile Size after purging : " (itoa FS2)))

 

You might also check to make sure the values are available 

(if FS1 (princ (strcat "\nFile Size before purging : " (itoa FS1))))

Message 3 of 5

Shneuph
Collaborator
Collaborator
Accepted solution

"Error: bad argument type: stringp nil"  Commonly seen error.  It means the program expects a sting but what it was given is not a string.

 

Your variables fs1 and fs2 are integers.  So, when you try to strcat them with a string it doesn't know what to do.  You have to convert it to a string before strcat-ing it like this:

 

(princ (strcat "\nFile Size before purging : " (ITOA FS1)))

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 5

Anonymous
Not applicable

Thank you mracad,

 

After making  change, now getting a different error.

 

error: bad argument type: fixnump: nil

 

I also checked if value for FS1 is available using if condition as you mentioned. It returned nil value. What other issues could be?

 

All we want to display message showing file size before purging and after purging.

 

Thanks again.

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

I found the error I was making.

 

Below code is the one that was returning the NIL value for file size.

 (setq fs1 (vl-file-size (getvar 'DWGNAME)))

 

Because (getvar 'DWGNAME) returns drawing file name only. We need whole file path to get the file size. So I modified routine with below and it worked.

 

(setq dirpath (getvar 'dwgprefix))
(setq fname (getvar 'dwgname))
(setq fpath (strcat dirpath fname))
(setq fs1 (vl-file-size fpath))

 

Thanks you mracad and Shneuph

 

 

 

 

 

0 Likes