+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Senior Member ksperopoulos's Avatar
    Computer Details
    ksperopoulos's Computer Details
    Operating System:
    Windows 8.1 Enterprise; 64-bit
    Computer:
    HP Elitebook 8760w
    RAM:
    16GB
    Graphics:
    NVIDIA Quadro 4000M
    Using
    AutoCAD 2016
    Join Date
    Feb 2009
    Location
    Kansas City, MO
    Posts
    438

    Default Repeat Last Command

    Registered forum members do not see this ad.

    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?

    Code:
     
    (repeat # [command])

  2. #2
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,199

    Default

    Based on the information you've provided, yes.

    eg.
    Code:
    (defun foo nil (entmakex (list '(0 . "LINE") '(10 0. 0. 0.) '(11 1. 1. 1.))))
    
    (repeat 5 foo)
    DropBox
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  3. #3
    Senior Member ksperopoulos's Avatar
    Computer Details
    ksperopoulos's Computer Details
    Operating System:
    Windows 8.1 Enterprise; 64-bit
    Computer:
    HP Elitebook 8760w
    RAM:
    16GB
    Graphics:
    NVIDIA Quadro 4000M
    Using
    AutoCAD 2016
    Join Date
    Feb 2009
    Location
    Kansas City, MO
    Posts
    438

    Default

    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?

  4. #4
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,199

    Default

    Quote Originally Posted by ksperopoulos View Post
    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.
    DropBox
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  5. #5
    Senior Member ksperopoulos's Avatar
    Computer Details
    ksperopoulos's Computer Details
    Operating System:
    Windows 8.1 Enterprise; 64-bit
    Computer:
    HP Elitebook 8760w
    RAM:
    16GB
    Graphics:
    NVIDIA Quadro 4000M
    Using
    AutoCAD 2016
    Join Date
    Feb 2009
    Location
    Kansas City, MO
    Posts
    438

    Default

    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.

  6. #6
    Senior Member ksperopoulos's Avatar
    Computer Details
    ksperopoulos's Computer Details
    Operating System:
    Windows 8.1 Enterprise; 64-bit
    Computer:
    HP Elitebook 8760w
    RAM:
    16GB
    Graphics:
    NVIDIA Quadro 4000M
    Using
    AutoCAD 2016
    Join Date
    Feb 2009
    Location
    Kansas City, MO
    Posts
    438

    Default

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

    Code:
     
    (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))

  7. #7
    Forum Deity
    Using
    AutoCAD 2009
    Join Date
    Oct 2008
    Posts
    2,112

    Default

    Quote Originally Posted by ksperopoulos View Post
    Why is it when I run this lisp it does not get everything out like when I manually type in the commands?

    Code:
     
    (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:

    Code:
    (defun c:scrubdwg2 ()
      (setvar "cmdecho" 0)
      (command "._-layer" "_s" "0" "")
      (repeat 3
        (command "._-purge" "_r" "" "_n")
        (command "._audit" "_y")
        (command "._-purge" "_a" "*" "_n")
      )
      (command "._zoom" "_e")
      (setvar "cmdecho" 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.

  8. #8
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Hi,

    Also you can use the following function to set a specific layer current ;
    Code:
    (setvar "clayer" "0")
    or this to recall the same current layer that was on.
    Code:
    (setq lay(getvar "clayer"))
    (setvar "clayer" "0")
    
    ; your codes are running here
    
    (setvar "clayer" lay)
    Just for more ideas.
    Regards.
    Tharwat

  9. #9
    Senior Member ksperopoulos's Avatar
    Computer Details
    ksperopoulos's Computer Details
    Operating System:
    Windows 8.1 Enterprise; 64-bit
    Computer:
    HP Elitebook 8760w
    RAM:
    16GB
    Graphics:
    NVIDIA Quadro 4000M
    Using
    AutoCAD 2016
    Join Date
    Feb 2009
    Location
    Kansas City, MO
    Posts
    438

    Default

    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.

    Code:
     
    (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))

  10. #10
    Forum Deity
    Using
    AutoCAD 2009
    Join Date
    Oct 2008
    Posts
    2,112

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by ksperopoulos View Post
    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.

    Code:
     
    (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/showth...ND+PURGE+AUDIT

    Code:
    (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.")

Similar Threads

  1. Repeat break command
    By Butch in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 16th Jul 2009, 05:06 pm
  2. Repeat Command Dropdown
    By dsibbo in forum AutoCAD General
    Replies: 2
    Last Post: 9th Apr 2009, 11:42 am
  3. Repeat last command insert block?!
    By Butch in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 14th Mar 2009, 12:02 pm
  4. Repeat last action?
    By Valce in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 23rd Jun 2008, 04:37 pm
  5. how do I repeat last input
    By mfranke in forum AutoCAD General
    Replies: 8
    Last Post: 23rd Nov 2007, 07:56 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts