Jump to content
ksperopoulos

Repeat Last Command

Recommended Posts

ksperopoulos

I am trying to repeat about 3 commands in a lisp I am putting together, but I am unsure how to do this. Is it as simple as doing this as shown in the AutoCad help file?

 

 
(repeat [color=red]#[/color] [color=red][color=black][[/color]command[/color][color=black]])[/color]

Share this post


Link to post
Share on other sites
alanjt

Based on the information you've provided, yes.

 

eg.

(defun foo nil (entmakex (list '(0 . "LINE") '(10 0. 0. 0.) '(11 1. 1. 1.))))

(repeat 5 foo)

Share this post


Link to post
Share on other sites
ksperopoulos

I know I have run across the need to purge unused information out of a drawing on average about 3 times before it all goes away. But I have also been noticing when I try to purge the regapps it also takes a couple tries to remove all of them. Same for running an audit. Do you run into the same problems or is there an easier way to get rid of the unwanted "junk" in my drawing files?

Share this post


Link to post
Share on other sites
alanjt
I know I have run across the need to purge unused information out of a drawing on average about 3 times before it all goes away. But I have also been noticing when I try to purge the regapps it also takes a couple tries to remove all of them. Same for running an audit. Do you run into the same problems or is there an easier way to get rid of the unwanted "junk" in my drawing files?

I have a simple routine that runs it 3 times a piece.

Share this post


Link to post
Share on other sites
ksperopoulos

That is what I have just done...3 times for purge regapps, purge all, and audit. Thanks for your help again! One day I might just get this stuff.

Share this post


Link to post
Share on other sites
ksperopoulos

Why is it when I run this lisp it does not get everything out like when I manually type in the commands?

 

 
(defun c:scrubdwg2 ()
;;; Delete all regapps, run an audit on the drawing file, and purge all unused items
    (setvar 'cmdecho 0)(repeat 3 (command "-purge" "r" "" "n")
    (command "audit" "y")
    (command "-purge" "a" "*" "n"))
;;; Zoom extents
    (command "zoom" "e")(setvar 'cmdecho 1)(princ))

Share this post


Link to post
Share on other sites
The Buzzard
Why is it when I run this lisp it does not get everything out like when I manually type in the commands?

 

 
(defun c:scrubdwg2 ()
;;; Delete all regapps, run an audit on the drawing file, and purge all unused items
    (setvar 'cmdecho 0)(repeat 3 (command "-purge" "r" "" "n")
    (command "audit" "y")
    (command "-purge" "a" "*" "n"))
;;; Zoom extents
    (command "zoom" "e")(setvar 'cmdecho 1)(princ))

I tried a couple of things, See below:

 

(defun c:scrubdwg2 ()
 (setvar [color="Red"]"[/color]cmdecho[color="red"]"[/color] 0)
 [color="red"](command "._-layer" "_s" "0" "")[/color]
 (repeat 3
   (command "[color="red"]._[/color]-purge" "[color="red"]_[/color]r" "" "[color="red"]_[/color]n")
   (command "[color="red"]._[/color]audit" "[color="red"]_[/color]y")
   (command "[color="red"]._[/color]-purge" "[color="red"]_[/color]a" "*" "[color="red"]_[/color]n")
 )
 (command "[color="Red"]._[/color]zoom" "[color="red"]_[/color]e")
 (setvar [color="red"]"[/color]cmdecho[color="red"]"[/color] 1)
 (princ))

 

Primary thing found.

I set the layer to 0 just in case an object that was removed had its layer set current.

If a layer other than 0 is set current and has no entities on it, You will not be able to purge that layer.

 

Just some extra things I found.

Added quotes around "cmdecho".

If your going to use command calls, Set the commands for language compatibility. This is an International site.

 

Just to mention, This will not work on some older versions of CAD since there is no regapps command.

Share this post


Link to post
Share on other sites
Tharwat

Hi,

 

Also you can use the following function to set a specific layer current ;

(setvar "clayer" "0")

or this to recall the same current layer that was on.

(setq lay(getvar "clayer"))
(setvar "clayer" "0")

; your codes are running here

(setvar "clayer" lay)

 

Just for more ideas.

Regards.

Tharwat

Share this post


Link to post
Share on other sites
ksperopoulos

I think I have incorporated the advice you guys have given. Here is what I have so far. I still come up with quite a few errors when I run the audit manually even though the lisp should audit the drawing file 3 times.

 

 
(defun c:scrubdwg (/ *error* uFlag)
    (vl-load-com)

    (defun *error* (msg)
    (and uFlag (vla-EndUndoMark *doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
    (princ (strcat "\n** Error: " msg " **")))
    (princ))
    (setq *doc (cond (*doc)((vla-get-ActiveDocument
    (vlax-get-acad-object)))))
;;; Set UCS to world
    (setvar "cmdecho" 0)(command "._ucsfollow" "1")
    (command "._ucs" "_w")(command "._ucsfollow" "0")
;;; Detach all xrefs
    (command "._-xref" "_D" "*")
;;; Delete all layout tabs
    (vlax-for lay  (vla-get-layouts *doc)
    (if (not (eq "MODEL" (strcase (vla-get-Name lay))))
    (vla-delete lay)))
;;; Changes all layers to thaw, on, unlock, and .25mm lineweight. Set current layer to 0.
    (command "._-layer" "_t" "*" "_on" "*" "_u" "*" "_s" "0" "_lw" "0.25" "*" "")
;;; Delete all layer filters
    (vl-catch-all-apply
    '(lambda ()
    (vla-remove
    (vla-getextensiondictionary
    (vla-get-layers
    (vla-get-activedocument (vlax-get-acad-object))
     ) ;_ end of vla-Get-Layers
     ) ;_ end of vla-GetExtensionDictionary
    "AcLyDictionary"
     ) ;_ end of vla-Remove
     ) ;_ end of lambda
     ) ;_ end of vl-Catch-All-Apply
;;; Delete all layer states
    (if (setq states (layerstate-getnames t t))
    (mapcar (function layerstate-delete) states))
;;; Delete all named views
    (command "._-view" "_s" "junk")(command "._-view" "_d" "*")
;;; Set insertion basepoint to 0,0,0
    (command "._insbase" "0,0,0")
;;; Set overall, modelspace, and paperspace linetype scales to 1
    (command "._ltscale" 1)(command "._msltscale" 1)(command "._psltscale" 1)
;;; Set annotation scale to 1/4" = 1'-0"
    (command "._cannoscale" "1/4\042 = 1'-0\042")
;;; Delete unused scales
    (command "._-scalelistedit" "_d" "*" "_e")
;;; Delete all dimensions
    (if (setq ss (ssget "_x" (list (cons 0 "*dimension"))))
        (command "_erase" ss "")
    )
;;; Set all object colors to bylayer
    (command "._setbylayermode" "1")
    (command "._setbylayer" "_all" "" "_y" "_y")
;;; Erase x data
    (command "._erase" (ssget"x") "r")(setvar 'cmdecho 1)(princ))
;---------------------------------------------------------------------------------------------------------
(defun c:scrubdwg2 ()
;;; Delete all regapps, run an audit on the drawing file, and purge all unused items
    (setvar "cmdecho" 0)
    (command "._-layer" "_s" "0" "")
    (repeat 3 
       (command "._-purge" "_r" "" "_n")
       (command "._audit" "_y")
       (command "._-purge" "_a" "*" "_n")
    )
;;; Zoom extents
    (command "._zoom" "_e")
    (setvar "cmdecho" 1)
    (princ))

Share this post


Link to post
Share on other sites
The Buzzard
I think I have incorporated the advice you guys have given. Here is what I have so far. I still come up with quite a few errors when I run the audit manually even though the lisp should audit the drawing file 3 times.

 

 
(defun c:scrubdwg (/ *error* uFlag)
    (vl-load-com)

    (defun *error* (msg)
    (and uFlag (vla-EndUndoMark *doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
    (princ (strcat "\n** Error: " msg " **")))
    (princ))
    (setq *doc (cond (*doc)((vla-get-ActiveDocument
    (vlax-get-acad-object)))))
;;; Set UCS to world
    (setvar "cmdecho" 0)(command "._ucsfollow" "1")
    (command "._ucs" "_w")(command "._ucsfollow" "0")
;;; Detach all xrefs
    (command "._-xref" "_D" "*")
;;; Delete all layout tabs
    (vlax-for lay  (vla-get-layouts *doc)
    (if (not (eq "MODEL" (strcase (vla-get-Name lay))))
    (vla-delete lay)))
;;; Changes all layers to thaw, on, unlock, and .25mm lineweight. Set current layer to 0.
    (command "._-layer" "_t" "*" "_on" "*" "_u" "*" "_s" "0" "_lw" "0.25" "*" "")
;;; Delete all layer filters
    (vl-catch-all-apply
    '(lambda ()
    (vla-remove
    (vla-getextensiondictionary
    (vla-get-layers
    (vla-get-activedocument (vlax-get-acad-object))
     ) ;_ end of vla-Get-Layers
     ) ;_ end of vla-GetExtensionDictionary
    "AcLyDictionary"
     ) ;_ end of vla-Remove
     ) ;_ end of lambda
     ) ;_ end of vl-Catch-All-Apply
;;; Delete all layer states
    (if (setq states (layerstate-getnames t t))
    (mapcar (function layerstate-delete) states))
;;; Delete all named views
    (command "._-view" "_s" "junk")(command "._-view" "_d" "*")
;;; Set insertion basepoint to 0,0,0
    (command "._insbase" "0,0,0")
;;; Set overall, modelspace, and paperspace linetype scales to 1
    (command "._ltscale" 1)(command "._msltscale" 1)(command "._psltscale" 1)
;;; Set annotation scale to 1/4" = 1'-0"
    (command "._cannoscale" "1/4\042 = 1'-0\042")
;;; Delete unused scales
    (command "._-scalelistedit" "_d" "*" "_e")
;;; Delete all dimensions
    (if (setq ss (ssget "_x" (list (cons 0 "*dimension"))))
        (command "_erase" ss "")
    )
;;; Set all object colors to bylayer
    (command "._setbylayermode" "1")
    (command "._setbylayer" "_all" "" "_y" "_y")
;;; Erase x data
    (command "._erase" (ssget"x") "r")(setvar 'cmdecho 1)(princ))
;---------------------------------------------------------------------------------------------------------
(defun c:scrubdwg2 ()
;;; Delete all regapps, run an audit on the drawing file, and purge all unused items
    (setvar "cmdecho" 0)
    (command "._-layer" "_s" "0" "")
    (repeat 3 
       (command "._-purge" "_r" "" "_n")
       (command "._audit" "_y")
       (command "._-purge" "_a" "*" "_n")
    )
;;; Zoom extents
    (command "._zoom" "_e")
    (setvar "cmdecho" 1)
    (princ))

Wow! you got an awful lot of command calls there. I can appreciate your honest attempt, But that process can only lead to headaches. Below is a code I believe was done by ASMI or Jeepmaster that will do a BIND, PURGE and AUDIT. I renamed the file to BPA. It works great. Try it and let us know what you think. I use this code with Lees Script Writing program for multiple drawings and what a time saver it is. If anything there may be answer for you here. Note that this code uses the system variable bindtype.

 

Here is the thread for your information:http://www.cadtutor.net/forum/showthread.php?t=13141&highlight=BIND+PURGE+AUDIT

 

(defun c:BPA (/ *error* oldBnType)

 (vl-load-com)
 (defun *error*(msg)
   (setvar "modemacro" ".")
   (setvar "bindtype" oldBnType)
   (setvar "cmdecho" 1)
   (princ "\nDetach/Audit/Bind/PurgeAll terminated  ")
   (princ)
   ); end of *error*
 
 (setq oldBnType(getvar "bindtype"))
 (setvar "modemacro" "Detach/Audit/Bind/PurgeAll processing......please wait......")
 (prompt "\n---Detach unloaded Xref, Audit, Bind, PurgeAll---")
 (prompt "\nDetaching...")
 (vlax-for block (vla-get-blocks
   (vla-get-activedocument
   (vlax-get-acad-object)))
     (if (and (= :vlax-true (vla-get-isxref block))
     (= 0 (vla-get-count block))
       )
     (vla-detach block)
     )
 )
 (setvar "cmdecho" 0)
 (prompt "...done")
 (prompt "\nAuditing...")(terpri)
 (command "_audit" "y")
 (prompt "\nBinding all Xrefs...")
 (setvar "bindtype" 1)
 (command "-xref" "b" "*")
 (prompt "...done")(terpri)
 (prompt "\nPurging #1")(terpri)
 (command "-purge" "a" "*" "N")
 (prompt "\nPurging #2")(terpri)
 (command "-purge" "a" "*" "N")
 (prompt "\nPurging #3")(terpri)
 (command "-purge" "a" "*" "N")
 (prompt "\n---Detach, Audit, Bind, PurgeAll completed!---")
 (setvar "modemacro" ".")
 (setvar "cmdecho" 1)
 (princ)
); end of c:BPA
(princ "\nBind, Purge & Audit Lisp loaded! Type BPA to start program.")

Share this post


Link to post
Share on other sites
ksperopoulos
Wow! you got an awful lot of command calls there. I can appreciate your honest attempt, But that process can only lead to headaches. Below is a code I believe was done by ASMI or Jeepmaster that will do a BIND, PURGE and AUDIT. I renamed the file to BPA. It works great. Try it and let us know what you think. I use this code with Lees Script Writing program for multiple drawings and what a time saver it is. If anything there may be answer for you here. Note that this code uses the system variable bindtype.

 

I know there is a lot to the lisp I am putting together, but we deal with some very large files while coordinating our 3d models with other contractors. I just gave it a test on one of the random files on a project I am working on and after running your BPA lisp it reduced the original file size (11 MB) down to 5.4 MB. But after I ran my lisp, it reduced the original file down to 2.3 MB. My lisp is a 2-part process that pauses only to manually delete unwanted objects/information out of the drawing that our company doesn't need. So the 2.3 MB drawing file would actually be less after we finished cleaning it up. The time it took to run the BPA lisp also took a lot longer to complete than my lisp did. I guess that can be attributed to reducing the amount of information in the drawing file prior to running some of the commands in the lisp. I appreciate your help and if there is anything that could make this easier or faster, I am definitely all ears.

Share this post


Link to post
Share on other sites
The Buzzard
I know there is a lot to the lisp I am putting together, but we deal with some very large files while coordinating our 3d models with other contractors. I just gave it a test on one of the random files on a project I am working on and after running your BPA lisp it reduced the original file size (11 MB) down to 5.4 MB. But after I ran my lisp, it reduced the original file down to 2.3 MB. My lisp is a 2-part process that pauses only to manually delete unwanted objects/information out of the drawing that our company doesn't need. So the 2.3 MB drawing file would actually be less after we finished cleaning it up. The time it took to run the BPA lisp also took a lot longer to complete than my lisp did. I guess that can be attributed to reducing the amount of information in the drawing file prior to running some of the commands in the lisp. I appreciate your help and if there is anything that could make this easier or faster, I am definitely all ears.

That may have something to do with the regapp function. The code I gave you does not have that. That could be the difference. Try to add it and see what happens. People will tell you that ASMI is an excellent programmer so I doubt there is something wrong with his code. Give that a shot and see.

 

I have been running that code and never had a problem with the end result.

Share this post


Link to post
Share on other sites
ksperopoulos

I would never question anybody's code mainly because I am so new to this that I probably couldn't tell you if it was wrong or right to begin with. You were right though. After running the regapp function, it got the drawing that I ran the BPA lisp on down to 3MB. Thanks for the help.

Share this post


Link to post
Share on other sites
The Buzzard
I would never question anybody's code mainly because I am so new to this that I probably couldn't tell you if it was wrong or right to begin with. You were right though. After running the regapp function, it got the drawing that I ran the BPA lisp on down to 3MB. Thanks for the help.

I am not sayin you are questionig it. I am only sayin give it the benefit of the doubt. I also realize many others do things that may seem odd to me, but I know who the experienced people are. Just like you I am also learning. Sometimes things need a second look. You will find here that everyone has their way of programming, We just need to adjust it to suit our own needs.

 

Anyway I hope it was helpful to you.

Good Luck with your coding. I admire people who go the distance.

The Buzzard

Share this post


Link to post
Share on other sites
ksperopoulos
Anyway I hope it was helpful to you.

Good Luck with your coding. I admire people who go the distance.

The Buzzard

 

Thanks! Same to you.

Share this post


Link to post
Share on other sites
mustaf

Thank you very much for this lisp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×