home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / may94cad.zip / SWEEP.LSP < prev    next >
Text File  |  1994-04-25  |  8KB  |  266 lines

  1. ;==========================================================
  2. ; SWEEP.LSP Copyright 1994 by Looking Glass Microproducts
  3. ;==========================================================
  4. ; Run a script file for every .DWG file in a directory 
  5. ;=============================================================
  6. (Defun c:sweep (/ dwgmod error notrans go_ahead dosdir get_sweep_list
  7.                 fprinc create_script_file sweep)
  8.    ;==========================================================
  9.    ; Display acad_dwgmod dialog box
  10.    ;==========================================================
  11.    (Defun dwgmod (/ dcl_id what_next)
  12.       (Setq dcl_id (Load_Dialog "acad.dcl"))
  13.       (If (Not (New_Dialog "acad_dwgmod" dcl_id))
  14.          (Exit)
  15.       )
  16.       (Action_Tile "cancel" "(done_dialog 0)")
  17.       (Action_Tile "save" "(done_dialog 1)")
  18.       (Action_Tile
  19.          "discard"
  20.          "(done_dialog 2)"
  21.       )
  22.       (Setq what_next (Start_Dialog))
  23.       (Unload_Dialog dcl_id)
  24.       what_next
  25.    )
  26.    ;==========================================================
  27.    ; Error Handler
  28.    ;==========================================================
  29.    (Defun error (s)
  30.       (If (Not
  31.              (Member
  32.                 S
  33.                 '("Function cancelled" "console break")
  34.              )
  35.           )
  36.          (Princ s)
  37.       )
  38.       (If fhand (Close fhand))
  39.       (Princ)
  40.    )
  41.    ;==========================================================
  42.    ; Disallow transparent invocation of routine.
  43.    ;==========================================================
  44.    (Defun notrans ()
  45.       (Cond
  46.          ((Zerop
  47.              (LogAnd
  48.                 (GetVar "cmdactive")
  49.                 (+ 1 2 4 8)
  50.              )
  51.           )
  52.          )
  53.          ((Alert
  54.              "This command may not be invoked transparently."
  55.           )
  56.          )
  57.       )
  58.    )
  59.    ;==========================================================
  60.    ; Go ahead with command? 
  61.    ;==========================================================
  62.    (Defun go_ahead ()
  63.       (Cond
  64.          ((Zerop (GetVar "dbmod"))
  65.             T ; nothing changed, go ahead
  66.          )
  67.          ((= 0 (Setq what_next (dwgmod)))
  68.             Nil ; cancel command
  69.          )
  70.          ((= 1 what_next)
  71.             ; save changes
  72.             (Command "_qsave")
  73.             (If (/= (GetVar "cmdactive") 0)
  74.                (Command "~")
  75.             )
  76.             T
  77.          )
  78.          ((= 2 what_next)
  79.             ; discard changes
  80.             T
  81.          )
  82.       )
  83.    )
  84.    ;==========================================================
  85.    ; Get Dos Directory
  86.    ;==========================================================
  87.    (Defun dosdir (filespec / dirfile dircmd fhand fnames lbuf)
  88.       (Setq
  89.          dirfile "_SWEEP_.DIR"
  90.          dircmd  (Strcat
  91.                     "dir /-p /-w /-a /-s /b /-l /o-n "
  92.                     filespec
  93.                     " >"
  94.                     dirfile
  95.                  )
  96.       )
  97.       (Command "_shell" dircmd)
  98.       (Cond
  99.          ((Null (Setq fhand (Open dirfile "r")))
  100.             (Alert
  101.                (Strcat dirfile ": Can't open file.")
  102.             )
  103.          )
  104.          (T
  105.             (While (Setq lbuf (Read-Line fhand))
  106.                (Setq fnames (Cons lbuf fnames))
  107.             )
  108.             (Close fhand)
  109.             (Setq fhand Nil)
  110.          )
  111.       )
  112.       fnames
  113.    )
  114.    ;==========================================================
  115.    ; Get Sweep List
  116.    ;==========================================================
  117.    (Defun get_sweep_list (/ sweepdir filelist)
  118.       (Cond
  119.          ((Null
  120.              (Setq
  121.                 sweepdir (GetFileD
  122.                             "Select Drawing Directory"
  123.                             "_select_"
  124.                             "dwg"
  125.                             3
  126.                          )
  127.              )
  128.           )
  129.          )
  130.          ((Progn
  131.              ; =====================================--
  132.              ; remove filename from directory
  133.              (While (WCmatch sweepdir "~*`\\")
  134.                 (Setq
  135.                    sweepdir (Substr
  136.                                sweepdir
  137.                                1
  138.                                (1- (Strlen sweepdir))
  139.                             )
  140.                 )
  141.              )
  142.              (Null
  143.                 (Setq
  144.                    filelist (dosdir (Strcat sweepdir "*.dwg"))
  145.                 )
  146.              )
  147.           )
  148.             (Alert
  149.                (Strcat
  150.                   "No drawing files found in "
  151.                   sweepdir
  152.                )
  153.             )
  154.          )
  155.          (T
  156.             (Setq
  157.                filelist (MapCar
  158.                            '(Lambda (x) (Strcat sweepdir x))
  159.                            filelist
  160.                         )
  161.             )
  162.          )
  163.       )
  164.       filelist
  165.    )
  166.    ;==========================================================
  167.    ; Print to file
  168.    ;==========================================================
  169.    (Defun fprinc (s) (Princ s fhand))
  170.    ;==========================================================
  171.    ; Create Script File
  172.    ;==========================================================
  173.    (Defun create_script_file (sweep_scr sweep_list big_scr / fhand
  174.                               lbuf lines fname line)
  175.       (Cond
  176.          ((Null (Setq fhand (Open sweep_scr "r")))
  177.             (Alert
  178.                (Strcat sweep_scr ": Can't read file.")
  179.             )
  180.          )
  181.          ((Progn
  182.              (While (Setq lbuf (Read-Line fhand))
  183.                 (Setq
  184.                    lines (Cons (Strcat lbuf "\n") lines)
  185.                 )
  186.              )
  187.              (Setq
  188.                 lines (Apply 'Strcat (Reverse lines))
  189.              )
  190.              (Close fhand)
  191.              (Setq fhand Nil)
  192.              (Null (Setq fhand (Open big_scr "w")))
  193.           )
  194.             (Alert
  195.                (Strcat big_scr ": Can't write file.")
  196.             )
  197.          )
  198.          (T
  199.             (ForEach fname sweep_list
  200.                (fprinc "_point (getvar \"limmin\")\n")
  201.                (fprinc (Strcat "open y " fname "\n"))
  202.                (fprinc lines)
  203.             )
  204.             (fprinc "_point (getvar \"limmin\")\n")
  205.             (fprinc "new y\n\n")
  206.             (fprinc "shell erase _sweep_.*\n")
  207.             (fprinc "(alert \"SWEEP Complete.\")(princ)\n")
  208.             (Close fhand)
  209.             (Setq fhand Nil)
  210.             T
  211.          )
  212.       )
  213.    )
  214.    ;==========================================================
  215.    ; Main Routine
  216.    ;==========================================================
  217.    (Defun sweep (/ sweep_list sweep_scr big_scr)
  218.       (Setq big_scr "_SWEEP_.SCR")
  219.       (Cond
  220.          ((Null (go_ahead)))
  221.          ((Null
  222.              (Setq
  223.                 sweep_scr (GetFileD
  224.                              "Select Script File"
  225.                              ""
  226.                              "scr"
  227.                              10
  228.                           )
  229.              )
  230.           )
  231.          )
  232.          ((Null
  233.              (Setq sweep_list (get_sweep_list))
  234.           )
  235.          )
  236.          ((Null
  237.              (create_script_file
  238.                 sweep_scr
  239.                 sweep_list
  240.                 big_scr
  241.              )
  242.           )
  243.          )
  244.          (T (Command "_script" big_scr))
  245.       )
  246.    )
  247.    ;==========================================================
  248.    ; Body of c:sweep  
  249.    ;==========================================================
  250.    (If (notrans)
  251.       (Progn
  252.          (Setq old-error *Error* *Error* error)
  253.          (Setvar "cmdecho" 0)
  254.          (sweep)
  255.       )
  256.    )
  257.    (Princ)
  258. )
  259. (Princ
  260.    (Strcat
  261.       "  SWEEP.LSP v1.0 (Copyright 1994 by "
  262.       "Looking Glass Microproducts) loaded."
  263.    )
  264. )
  265. (Princ)
  266.