Jump to content
kennyutk

Beginner with LISP - Purge Blocks

Recommended Posts

kennyutk

Hello. I hope you guys can help with my LISP. I am new to this, so forgive me if I sound too basic.

 

A problem occurred all of a sudden, and it was working before. Now, when I open a dwg, it stalls at this portion of my acad file. That is how I narrowed it down to this particular LISP.

 

I can see my maps, but they are stalled. After about 1 minute, it says that there is a "Fatal Error - Out of Memory".

 

Do you guys have any idea on what to do?

 

If I take out the "N" portion on this line (command "purge" "block" "*" "N"), it seems to work, but I have to click through several options in my command line to do anything on my map.

 

(defun T:PURGEBLOCK ()

(if (and (/= (getvar "dwgname") "unnamed")(/= (substr (getvar "dwgname") 1 7) "Drawing"))

(progn

(setq wts (getvar "writestat"))

(if (/= wts 0)

(progn

(command "purge" "block" "*" "N")

(setq chg (getvar "dbmod"))

(if (/= chg 0)

(progn

(setvar "cmdecho" 0)

(princ "\n Saving purged drawing \n")

(setvar "expert" 3)

(command "save" "")

(setvar "expert" 0)

; (snd)

);end progn

);end if

);end progn

);end if

);end progn

);end if

(setvar "cmdecho" 0)

(princ)

)

Share this post


Link to post
Share on other sites
BIGAL

Try this -purge

Share this post


Link to post
Share on other sites
kennyutk

Hello. Sorry but where in my LISP should I try that?

Share this post


Link to post
Share on other sites
Lee Mac

Try the following (untested) code:

(defun purgeblock ( / val var )
   (if (= 1 (getvar 'dwgtitled) (getvar 'writestat))
       (progn
           (setq var '(cmdecho expert)
                 val  (mapcar 'getvar var)
           )
           (mapcar 'setvar var '(0 2))
           (command "_.-purge" "_b" "*" "_n")
           (if (< 0 (getvar 'dbmod))
               (progn
                   (command "_.save" "")
                   (princ "\nPurged drawing saved.")
               )
               (princ "\nNothing to purge, drawing not saved.")
           )
           (mapcar 'setvar var val)
       )
       (princ "\nDrawing unsaved or read-only.")
   )
   (princ)
)

Share this post


Link to post
Share on other sites
kennyutk

Thank you. I will try this out!

 

 

 

 

Try the following (untested) code:

(defun purgeblock ( / val var )
   (if (= 1 (getvar 'dwgtitled) (getvar 'writestat))
       (progn
           (setq var '(cmdecho expert)
                 val  (mapcar 'getvar var)
           )
           (mapcar 'setvar var '(0 2))
           (command "_.-purge" "_b" "*" "_n")
           (if (< 0 (getvar 'dbmod))
               (progn
                   (command "_.save" "")
                   (princ "\nPurged drawing saved.")
               )
               (princ "\nNothing to purge, drawing not saved.")
           )
           (mapcar 'setvar var val)
       )
       (princ "\nDrawing unsaved or read-only.")
   )
   (princ)
)

Share this post


Link to post
Share on other sites
kennyutk

Both of the codes have the same error. It seems to only happen with my larger maps. Here is screenshot, but I'm not sure if that will help...

 

 

 

 

It will get stuck at those point and eventually lock up.

 

 

Could it be a different problem possibly?

 

 

Thank you. I will try this out!

Capture.PNG

Share this post


Link to post
Share on other sites
kennyutk

I should mention that if I change the code portion of

 

 

(command "_.-purge" "_b" "*" "_n") to

 

 

(command "_.-purge" "_b" "*" "_y")

 

 

it seems to work.

 

 

Is there any reason why I should use _n or _y? It seems that it is to just verify the name to be purged?

 

 

Try the following (untested) code:

(defun purgeblock ( / val var )
   (if (= 1 (getvar 'dwgtitled) (getvar 'writestat))
       (progn
           (setq var '(cmdecho expert)
                 val  (mapcar 'getvar var)
           )
           (mapcar 'setvar var '(0 2))
           (command "_.-purge" "_b" "*" "_n")
           (if (< 0 (getvar 'dbmod))
               (progn
                   (command "_.save" "")
                   (princ "\nPurged drawing saved.")
               )
               (princ "\nNothing to purge, drawing not saved.")
           )
           (mapcar 'setvar var val)
       )
       (princ "\nDrawing unsaved or read-only.")
   )
   (princ)
)

Share this post


Link to post
Share on other sites
kennyutk

Sorry, here is the link where I saw the information.

 

 

http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-C3876E92-3478-449C-8FAB-DA760B2EDD09

 

 

 

 

I should mention that if I change the code portion of

 

 

(command "_.-purge" "_b" "*" "_n") to

 

 

(command "_.-purge" "_b" "*" "_y")

 

 

it seems to work.

 

 

Is there any reason why I should use _n or _y? It seems that it is to just verify the name to be purged?

Share this post


Link to post
Share on other sites
kennyutk

let me try again

 

 

(defun T:PURGEBLOCK ()
   (if (and (/= (getvar "dwgname") "unnamed")(/= (substr (getvar "dwgname") 1 7) "Drawing"))
     (progn
      (setq wts (getvar "writestat"))
       (if (/= wts 0)
          (progn
           (command "purge" "block" "*" "N")
           (setq chg (getvar "dbmod"))
             (if (/= chg 0)
              (progn
               (setvar "cmdecho" 0)
               (princ "\n  Saving purged drawing \n")
               (setvar "expert" 3)
               (command "save" "")
               (setvar "expert" 0)
;                (snd)
              );end progn
             );end if
          );end progn
);end if
     );end progn
   );end if
(setvar "cmdecho" 0)
(princ)
)

Share this post


Link to post
Share on other sites
Lee Mac
I should mention that if I change the code portion of

 

(command "_.-purge" "_b" "*" "_n") to

 

(command "_.-purge" "_b" "*" "_y")

 

it seems to work.

 

Is there any reason why I should use _n or _y? It seems that it is to just verify the name to be purged?

 

As far as I am aware, the code I have posted is correct & should perform successfully; I would therefore hazard a guess that your drawings must contain a huge number of blocks to be purged, which is consequently causing AutoCAD to exhaust the available memory whilst attempting to purge all such blocks simultaneously (hence the reason that confirming each block to be purged alleviates the problem).

 

I would suggest using the following program to WBLOCK your entire drawing; the following code will generate a copy of the drawing in the working directory, with all unnecessary components removed:

(defun c:wba ( / dwg fnm tmp )
   (setq fnm
       (strcat
           (getvar 'dwgprefix)
           (cadr (fnsplitl (getvar 'dwgname)))
           "_wblock"
       )
   )
   (if (findfile (setq dwg (strcat fnm ".dwg")))
       (progn
           (setq tmp 1)
           (while (findfile (setq dwg (strcat fnm "(" (itoa (setq tmp (1+ tmp))) ").dwg"))))
       )
   )
   (command "_.wblock" dwg "*")
   (princ)
)

This method usually resolves most issues.

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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