Jump to content

Super purge lisp only works some of the time


Recommended Posts

Posted

So I am having trouble with a lisp routine that I wrote to purge everything from a drawing. The issue has to deal with the wblock command. It seems to work about half of the time, and then the other half of the time it errors on the _Y portion of the code, which I am confused by. My code is as follows

(defun c:superpurge (/ file path pathfile *error* oldecho olddia)
 (vl-load-com)
 (defun *error* (msg)   ;This defines the error function so that if something goes wrong, it exits quietly and resets the variables
   (if oldecho
     (setvar 'cmdecho oldecho)
   )
   (if olddia
     (setvar 'CMDDIA olddia)
   )
   (if (not
  (member msg '("Function cancelled" "quit / exit abort"))
)
     (princ (strcat "\nError: " msg))
   )
   (princ)
 )
 (setq oldecho (getvar 'CMDECHO)) ;I am setting the variable oldecho equal to the variable cmdecho
 (setvar "CMDECHO" 0)
 (setq olddia (getvar 'CMDDIA))
 (setvar "CMDDIA" 0)
 (cond
   ((or (= (getvar 'writestat) 0) ;If the drawing is read only or hasn't ever been saved ie Drawing1, then it won't run 
 (= (getvar 'DWGTITLED) 0)
    )
    (alert
      "\n Superpurge cannot be used in files that haven't been named or are read only."
    )
   )
   (t     ;This is the "else" portion of the cond statement
    (setq file (getvar "DWGNAME")) ;This gets the drawing name
    (setq path (getvar "DWGPREFIX")) ;This gets the drawing's path
    (setq pathfile (strcat path file)) ;This combines the two variables into one
    (repeat 3
      (vl-cmdf "._AECCPURGESTYLES")
      (while (eq (logand (getvar "cmdactive") 1) 1)
 (command "_Y")
      )
    )
    (command "._PURGE" "_A" "*" "_N")
    (command "._PURGE" "_R" "*" "_N")
    (command-s "-WBLOCK" pathfile "_Y" "*" "_Y")
    ;Here I am running wblock and saving over the current drawing
    (princ "\nYour drawing is now squeaky clean")
   )
 )
 (setvar "CMDECHO" oldecho)  ;Resetting the variable cmdecho to its original value
 (setvar "CMDDIA" olddia)
 (princ)    ;Exit quietly
)

Posted

So I have kept messing with it and read through the code numerous times and I can't find any errors. There doesn't seem to be any rhyme or reason for when it does and doesn't want to work, just that the wblock command doesn't want to always work. The only other improvement I can think of for the code is changing my repeat function for purging the styles into a while not statement that stops when purge styles gives "There are no unused styles." Is there a way to right a while statement that would accomplish this? I choose to do a repeat length of 3 just because I had never seen a scenario where I had to run it more than 3 times, but it would be more desirable to not have to run it Aeccpurgestyles again if there isn't a need because this is the slowest portion of the code.

Posted

Dunno about de rest of the code but I alwayz hated all the command echo's and so now I use

 

 

 (defun LG_Purge () (vla-purgeall (vla-get-activeDocument (vlax-get-acad-object)))) 

 

 

And you can call this function as often as you want.

 

 

Gr. Rlx

Posted
 (defun LG_Purge () (vla-purgeall (vla-get-activeDocument (vlax-get-acad-object)))) 

Be aware that this method will ignore redundant MLeader Styles.

Posted
Be aware that this method will ignore redundant MLeader Styles.
RLX, thank you for that code, that is a useful way to get around the command echo's (I find them pretty obnoxious). Lee, so does the code miss all types of styles, like all the AECC styles (surface styles, line and curve, etc.), or only mleader styles? Lee, I tried to write a loop for the purge styles portion, but it doesn't keep going until every style is purged as I had hoped
(while (not whilestop)
   (setq whilestop t)
   (vl-cmdf "._AECCPURGESTYLES")
   (if (getvar "WRITESTAT")
     (command "_Y")
   )
   (while (= (logand 1 (getvar "CMDACTIVE")) 1)
     (command "_Y")
     (setq whilestop nil)
   )
 )

Posted
RLX, thank you for that code, that is a useful way to get around the command echo's (I find them pretty obnoxious). Lee, so does the code miss all types of styles, like all the AECC styles (surface styles, line and curve, etc.), or only mleader styles? Lee, I tried to write a loop for the purge styles portion, but it doesn't keep going until every style is purged as I had hoped
(while (not whilestop)
   (setq whilestop t)
   (vl-cmdf "._AECCPURGESTYLES")
   (if (getvar "WRITESTAT")
     (command "_Y")
   )
   (while (= (logand 1 (getvar "CMDACTIVE")) 1)
     (command "_Y")
     (setq whilestop nil)
   )
 )

 

I used to use

 (command "-purge" "all" "*" "no") 

 

you can als search for purger.lsp on http://jtbworld.com/autocad-purger-lsp

 

gr. Rlx

Posted
Lee, so does the code miss all types of styles, like all the AECC styles (surface styles, line and curve, etc.), or only mleader styles?

 

I'm afraid I couldn't say - I don't have experience working with the Vertical applications.

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