Author Topic: Open XREF's, Run Command, Save, Close  (Read 2558 times)

0 Members and 2 Guests are viewing this topic.

walabash

  • Guest
Open XREF's, Run Command, Save, Close
« on: November 07, 2011, 12:00:20 PM »
I've created an ACTION in autocad that works like we want it to in a drawing (purges, audits, resets layer filters and scale lists, deletes a couple layers), but now I would like to make a script or lisp that would open a file, run the command, then open each of the files that are xrefed into it in turn and run the command on each of them, save and close them, and finally reload all xrefs in the original.

I'm kind of stuck with where to begin as I'm not good with this stuff and usually just stumble around until I find my way. LOL.

Any help is appreciated.  Thanks.

walabash

  • Guest
Re: Open XREF's, Run Command, Save, Close
« Reply #1 on: November 07, 2011, 01:58:52 PM »
Ok... I've got something that works well

Code: [Select]
(defun c:CleanMe
   (/ UserFile UserCat FileList File#1 DwgName FileName)
  (vl-load-com)
  (setq UserFile
  (getfiled "Select a drawing within the directory to process"
"c:/"
"dwg"
16
  )
  )
  (setq UserCat (vl-filename-directory UserFile))
  (setq FileList (vl-directory-files UserCat "*.dwg" 1))
  (setq File#1 (open "S:\Design\CAD\lisp\Clean.scr" "w"))
  ;; open/make a scriptfile to write to
  (foreach DwgName FileList
(setq FileName (strcat "\"" UserCat "\\" DwgName "\""))
(princ "open\n" File#1)
(princ (strcat FileName "\n") File#1)
;;Below are commands to run on each drawing...
(princ "-purge\n" File#1)
(princ "A\n" File#1)
(princ "*\n" File#1)
(princ "N\n" File#1)
(princ "-purge\n" File#1)
(princ "R\n" File#1)
(princ "*\n" File#1)
(princ "N\n" File#1)
(princ "audit\n" File#1)
(princ "Y\n" File#1)
(princ "XREFDET\n" File#1)
(princ "DLF\n" File#1)
(princ "-SCALELISTEDIT\n" File#1)
(princ "R\n" File#1)
(princ "Y\n" File#1)
(princ "E\n" File#1)
(princ "-LAYDEL\n" File#1)
(princ "N\n" File#1)
(princ "Defpoints\n" File#1)
(princ "\n" File#1)
(princ "Y\n" File#1)
(princ "_.qsave\n" File#1)
(princ "_.close\n" File#1)
  )
  (close File#1)
  (command "script" "S:\Design\CAD\lisp\Clean.scr")
  (princ)
)
(princ "\nCleanMe loaded.")
(princ)

All I need now is a check to see if defpoints exists and if not, to skip that portion of the code.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Open XREF's, Run Command, Save, Close
« Reply #2 on: November 07, 2011, 02:03:19 PM »
Just a side note... the command RECOVERALL will recover all (clever, huh?) xref'd files.  In case you ever need to do that.  :)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

KewlToyZ

  • Guest
Re: Open XREF's, Run Command, Save, Close
« Reply #3 on: November 08, 2011, 12:04:26 PM »
There was a browse for folder routine by Tony Tanzillo & Tim Wiley on here that batched out entire folders I used from time to time for a lot of routines.

Code: [Select]
;; To Batch Drawings removing errors ......
;;
;; Note: replace the Path/filename below to call up your Lisp
;;       to process the drawings the way you want.
;;
;; Make sure your lisp program is in a 'support' folder ..
;; Setup to batch specific project drawing files and prevent any non illiterate from destroying a project
(autoload "bataec" '("bataec"))

(setq my_lisp_file "bataec.lsp"); Place your specific lisp here !
(alert "This utility cleans up file formats and errors for AMEP use")
;; Load Supporting Functions
;; Old Version of 'BrowseForFolder' by: Tony Tanzillo
(defun BrowseForFolder ( Message / sh folder parentfolder folderobject result)
 (vl-load-com)
  (setq sh
   (vla-getInterfaceObject
     (vlax-get-acad-object)
       "Shell.Application"
     )
   )


   (setq folder
      (vlax-invoke-method
          sh
          'BrowseForFolder
          0
          Message
          0
       )
   )
   (vlax-release-object sh)


    (if folder
      (progn
         (setq parentfolder
           (vlax-get-property folder 'ParentFolder)
         )
        (setq FolderObject
           (vlax-invoke-method
              ParentFolder
               'ParseName
              (vlax-get-property Folder 'Title)
           )
        )
       (setq result
          (vlax-get-property FolderObject 'Path)
       )
       (mapcar 'vlax-release-object
         (list folder parentfolder folderobject)
       )
     (if (/= (substr result (strlen result)) "\\")
       (setq result (strcat result "\\"))
       result
     )
   )
 )
); defun

(defun C:BATCHAEC ()
;; portions by Tim Willey
  (if (setq DirPath (BrowseForFolder "Select directory to batch drawings."))
   (progn
    (setq DwgList (vl-directory-files DirPath "*.dwg" 1))
    (setq ScrFile (strcat DirPath "batchme.scr"))
    (setq Ofil (open ScrFile "W"))
    ;(setq Ofil (open ScrFile "R"))
     (write-line "SDI 0" Ofil); Force Multi-Document mode
     (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") Ofil)


;; Check for specific project drawing names starting with "Z0001"..
;; Edit this line for your specific batch

     (foreach Dwg DwgList
      ;;(if (= (substr Dwg 1 5) "P0604")
       (progn
        (setq FullPath (strcat DirPath Dwg))
        (write-line (strcat "_.open " (chr 34) FullPath (chr 34)) Ofil)
        (write-line (strcat "(load " (chr 34) my_lisp_file (chr 34) ")") Ofil)
        (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") Ofil)
        (write-line "_.bataec" Ofil)
        (write-line "_.qsave" Ofil)
        (write-line "_.close" Ofil)
        ;(write-line "Yes" Ofil)
       ); progn
      ;;); if
     ); foreach
     (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") Ofil)
     (close Ofil)
     (command "_.script" ScrFile)
   ); progn
  ); if
 (princ)
); function
 (prompt "\nType BATCHAEC to begin the batch process:")
 (princ)