Jump to content

Script Writer 1.2 with AutoCAD LT 2024


Recommended Posts

Posted

Hi All, I've started using the AutoCAD LT 2024. As I had a limited access to full CAD only, I was using rather simple scripts which work on LT, but for some repetitive tasks I used to use Lee Mac's Script Writer 1.2. So now, I would like to try this lisp with the LT version.
Sadly unsuccessfully... When trying to choose the folder by clicking on "Directory" button the whole script crashed with info about "Automation Error. No Description provided"... Do you have any idea what could be causing this? And is there a chance to fix it or LT still has some limitations, so the lisp simply won't work? At the moment I have access neither to full CAD nor to the Visual LISP Editor to debug the code...

 

WScript generally works, however when you run it the first time, it added extra backslashes to the path, like "C:\\Users\\name\\Documents\\". This causes an error, because it creates a wrong path in the script file (.scr) with double backslashes before the file name. But changing the path manually in a config file (without these end backslashes)... it works like a charm ;)

 

I also noticed that DOS Library (DOSLib24x64) cannot be loaded into LT 2024, so in script where DOSLib functions are used, they had to be changed to AutoLISP ones, like "dos_delete" to "vl-file-delete". But Lee's script is so complex (at least for me), so I was not able to find and fix the error. Any advice?

Posted

The issue is because the LISP API in AutoCAD LT cannot interface with ActiveX objects outside of the AutoCAD object model (in this case, the Windows Shell Object, used to display the 'Browse for Folder' dialog).

 

I could redesign the Script Writer program to allow the user to select a drawing within the folder to be processed (using a standard file selection dialog, thus compatible on LT), but to be honest, given the age of the application and the other bugs present in some of the features, the entire program really needs to be rewritten.

Posted (edited)

Depending on how many scripts you intend to write, years ago before Scriptwriter you made scripts manually, you can make a list of dwg names using Windows sending to a text file. Then you open the file in say Word or Notepad++. You can replace the end of line with like \rOpen . This will add Open to every line in your text file, for Word replace ^p  ^pOpen .

 

So using end of line you can add quickly to start or end of a line extra information. For multi lines you make one big line then add some end of lines eg ^p for word, so making a multi line script.

 

One warning if using Word copy and paste to Notepad then save as Word contains hidden characters.

 

This was the way it was done when Autocad was like version 1.4.

 

Now you have lisp it may be easier to just have simple scripts do all the extra steps in a lisp.

Open dwg1 (load "dothis)

Open dwg2 (load "dothis")

 

Happy to provide info about get dwg list to text file. Ps can get subdirectories also.

 

Edited by BIGAL
Posted
23 hours ago, Lee Mac said:

I could redesign the Script Writer program to allow the user to select a drawing within the folder to be processed (using a standard file selection dialog, thus compatible on LT), but to be honest, given the age of the application and the other bugs present in some of the features, the entire program really needs to be rewritten.

 

Thanks Lee Mac for the response. Yes, it's quite old stuff, but still does the job. I will think about using the standard file selection or simply change the dialog box to manually add the path. As I said, because the dialog box read the config file prior to open I can also change the folder in this text file...
 

Posted
20 hours ago, BIGAL said:

Depending on how many scripts you intend to write, years ago before Scriptwriter you made scripts manually, you can make a list of dwg names using Windows sending to a text file. Then you open the file in say Word or Notepad++. You can replace the end of line with like \rOpen . This will add Open to every line in your text file, for Word replace ^p  ^pOpen .

[...]

 

Thanks BIGAL, I was thinking about doing the multiline script manually in Notepad, but than a dialog box is just neater. As I said I can change the path in a config file and the script works, so I was just looking for a something more useful :)

Posted
On 9/26/2023 at 2:51 AM, Blackfish said:

Hi All, I've started using the AutoCAD LT 2024. As I had a limited access to full CAD only, I was using rather simple scripts which work on LT, but for some repetitive tasks I used to use Lee Mac's Script Writer 1.2. So now, I would like to try this lisp with the LT version.
Sadly unsuccessfully... When trying to choose the folder by clicking on "Directory" button the whole script crashed with info about "Automation Error. No Description provided"... Do you have any idea what could be causing this? And is there a chance to fix it or LT still has some limitations, so the lisp simply won't work? At the moment I have access neither to full CAD nor to the Visual LISP Editor to debug the code...

 

WScript generally works, however when you run it the first time, it added extra backslashes to the path, like "C:\\Users\\name\\Documents\\". This causes an error, because it creates a wrong path in the script file (.scr) with double backslashes before the file name. But changing the path manually in a config file (without these end backslashes)... it works like a charm ;)

 

I also noticed that DOS Library (DOSLib24x64) cannot be loaded into LT 2024, so in script where DOSLib functions are used, they had to be changed to AutoLISP ones, like "dos_delete" to "vl-file-delete". But Lee's script is so complex (at least for me), so I was not able to find and fix the error. Any advice?

 

LISPS + LT just dont go together. the LT version of autocad prevents you from doing so many things. my advice is to not spend time trying to get lisps working with LT. Have a look into bricscad for an autocad alternative which can use lisps

Posted
2 hours ago, Hữu Quốc said:

 

Just for my information, what did you change from Lee Macs original? (to be fair, I haven't had a chance this morning to try your version)

Posted

C:\XXX\XXX\AppData\Roaming\Autodesk\AutoCAD LT 2024\R30\enu\Support

Posted

That would surprise me if you needed to delete a file to make it all work - Lee Mac is usually very good with things like that. If the OP has only just downloaded the LISP then these files should be all up to date.

 

What I was asking is what did you change in the code to make the one you posted (scriptwriterv1-2_Quoc.lsp) different from the one from Lee Macs website (that the OP was using)

Posted

The issue I see with trying to write a script, what about more than 1 line needed ? After having a play it is very possible to get a list of dwg's in a directory.

 

(setq SavePath (getfiled "Pick a  File in a directory " "d:\\" "dwg" 16))
(setq SavePath (vl-filename-directory SavePath))
(setq dwgs (vl-directory-files "d:/acadtemp" "*.dwg"))

 

So next step would be to write a scr file asking 1st line, 2nd line and so on then adding dwg names.

 

So Blackfish when you say want to run a script do you really mean running a Lisp file on the current dwg ? As you now dont need scripts. Or doing a task on multiple dwg's ? Please clarify before we all "Go down the Garden path" hint +.lsp.

Posted
On 9/28/2023 at 10:14 AM, BIGAL said:
(setq SavePath (getfiled "Pick a  File in a directory " "d:\\" "dwg" 16))
(setq SavePath (vl-filename-directory SavePath))
(setq dwgs (vl-directory-files "d:/acadtemp" "*.dwg"))

 

So next step would be to write a scr file asking 1st line, 2nd line and so on then adding dwg names.

 

Nice, will think about these in the future... 

 

On 9/28/2023 at 10:14 AM, BIGAL said:

So Blackfish when you say want to run a script do you really mean running a Lisp file on the current dwg ? As you now dont need scripts. Or doing a task on multiple dwg's ? Please clarify before we all "Go down the Garden path" hint +.lsp.

 

Sorry, I'm a bit too busy to write more (or answer faster), but that's what I mean about doing a task (run a .scr script) on multiple dwgs.
Something like this in the WScript's script line (when save and close is in the script):
 

_.open *file* _.scriptcall "C:\temp\myscr.scr"

 

Posted

I would look at 

_.open *file* (load "mylisp")

 

It's easier some times to run a lisp than use a script you can do more complex stuff simpler. 

Posted
On 10/1/2023 at 12:45 AM, BIGAL said:

I would look at 

_.open *file* (load "mylisp")

 

It's easier some times to run a lisp than use a script you can do more complex stuff simpler. 

Thanks for that. It makes sense, but sometimes you have no time (being not so fluent in lisp) but have a working simple script (which was used originally on LT) and want run on multiple files only. Probably all will move from scr to lisp gradually anyway...

Posted (edited)

Not sure if this would work on LT - a DCL interface but in the background writes a script file saved in your windows temporary files location. Quite a lot in there and it might not work as is - bound to have forgotten some routine or other. The process is slower than other batches (but quick enough to buy me time for a coffee), opens each drawing, modifies, saves and closes as required with the benefit that .bak files will be created as the file was... just in case.... Won't run on opened drawings.

 

Command: Batchlisps

 

Interested to know if this works on LT more than anything.

 

A program I made up for myself, some parts are not as refined as I want

 

 

;;;;;;;;;;;;;;;;;-- referenced routines ---;;;;;;;;;;;;;;;;;;;;;
;;Note: LM prefix refers to Lee Mac Programming LISP routines ;;
;;      Otherwise reference sources are indicated             ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(vl-load-com)

;;;;;;;;;;;;;     Downloaded Routines      ;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;; --- NOT USED --- ;;;;;;;;;;;;
(defun LM:open ( target / rtn shl )
  (if (and (or (= 'int (type target)) (setq target (findfile target)))
    (setq shl (vla-getinterfaceobject (vlax-get-acad-object) "shell.application"))
    )
    (progn
      (setq rtn (vl-catch-all-apply 'vlax-invoke (list shl 'open target)))
      (vlax-release-object shl)
      (if (vl-catch-all-error-p rtn)
        (prompt (vl-catch-all-error-message rtn))
        t
      )
    )
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;; --- USED --- ;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
        pth
    )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;http://forums.augi.com/showthread.php?69609-List-dwg-s-from-all-subdirectories
(defun GrabAllFiles (Path FileExt / file tempPath FileList)
 (setq Path
  (if (= (substr Path (strlen Path)) "\\")
   Path
   (strcat Path "\\")
  )
 )
 (foreach file (vl-directory-files Path)
  (setq tempPath (strcat Path file))
   (if
    (not
     (or
      (= file ".")
      (= file "..")
     )
    )
    (if (vl-file-directory-p tempPath)
     (setq FileList (append FileList (GrabAllFiles tempPath FileExt)))
     (if (= (strcase FileExt) (strcase (vl-filename-extension tempPath)))
     (setq FileList (cons tempPath FileList))
    )
   )
  )
 )
 FileList
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun LM:GetSyntax ( file / _GetSyntax line syntax )
 (defun _GetSyntax ( p s / x )
  (if (setq x (vl-string-search p s))
   (cons
    (substr (setq s (substr s (+ x 1 (strlen p)))) 1
     (setq x
      (car
       (vl-sort
        (vl-remove 'nil
         (mapcar
          (function
           (lambda ( d ) (vl-string-position d s))
          )
          '(32 9 40 41)
         )
        )
        '<
       )
      )
     )
    )
   (if x (_GetSyntax p (substr s (1+ x))))
   )
  )
 ) 

 (if (setq file (open file "r"))
  (apply 'append
   (progn
    (while (setq line (read-line file))
     (setq syntax (cons (_GetSyntax "(DEFUN C:" (strcase line)) syntax))
    )
    (setq file (close file)) (reverse syntax)
   )
  )
 )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun LM:str->lst ( str del / pos ) ;;String to List
  (if (setq pos (vl-string-search del str))
    (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
    (list str)
  )
)

(defun LM:lst->str ( lst del / str ) ;;List to String
  (setq str (car lst))
  (foreach itm (cdr lst) (setq str (strcat str del itm)))
  str
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun LM:RemoveNth ( n l / i )
  (setq i -1)
  (vl-remove-if '(lambda ( x ) (= (setq i (1+ i)) n)) l)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun LM:StringSubst ( new old str / inc len )
  (setq len (strlen new)
    inc 0
  )
  (while (setq inc (vl-string-search old str inc))
    (setq str (vl-string-subst new old str inc)
      inc (+ inc len)
    )
  )
  str
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;https://www.theswamp.org/index.php?topic=41680.0
(defun replace-n (new n replacelst / )
  (mapcar '(lambda (a) (if (= (setq n (1- n)) -1) new a)) replacelst)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;      Custom Routines       ;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun resetDCLfiles()
  (if (strcat (getvar "TEMPPREFIX") "saveoption.dcl")(vl-file-delete (strcat (getvar "TEMPPREFIX") "saveoption.dcl")))
  (if (strcat (getvar "TEMPPREFIX") "BatchLisps.dcl")(vl-file-delete (strcat (getvar "TEMPPREFIX") "BatchLisps.dcl")))
  (if (strcat (getvar "TEMPPREFIX") "EditOptionsScript.dcl")(vl-file-delete (strcat (getvar "TEMPPREFIX") "EditOptionsScript.dcl")))
  (if (strcat (getvar "TEMPPREFIX") "EditScript.dcl")(vl-file-delete (strcat (getvar "TEMPPREFIX") "EditScript.dcl")))
  (if (strcat (getvar "TEMPPREFIX") "EditFileList.dcl")(vl-file-delete (strcat (getvar "TEMPPREFIX") "EditFileList.dcl")))
  (princ)
)


(defun c:resetbatchlisp() ;;if it all hangs up try this
  ;;Delete temp DCL Files
  (resetDCLfiles)

  ;;Delete Temp scr files:
  (if (strcat (getvar "TEMPPREFIX") "myscr.scr")(vl-file-delete (strcat (getvar "TEMPPREFIX") "myscr.scr")))
  (if (strcat (getvar "TEMPPREFIX") "tempbatchscrpt.scr")(vl-file-delete (strcat (getvar "TEMPPREFIX") "tempbatchscrpt.scr")))

  ;;Delete other temp files
  (if (strcat (getvar "TEMPPREFIX") "savescr.lsp")(vl-file-delete (strcat (getvar "TEMPPREFIX") "savescr.lsp")))
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun selectfolder ( path / SFMyDir)
  (setq SFMyDir (LM:browseforfolder "Select a folder" "SFMyDir" 0))

  (if (= SFMyDir Nil)
    (progn
      (setq SFMyDir path)
    )
    (progn
      (princ "OK")
    );;end progn
  );; end if

  SFMyDir

)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun saveoptionsscr ( saveoptions / version VERSIONS FILEVERSIONS prefix suffix path saveoption des x dch saveasversion)

  (setq VERSIONS '("" "2018" "2013" "2010" "2007" "2004" ))  ;define list
  (setq FILEVERSIONS '("" "2018" "2013-2017" "2010-2012" "2007-2009" "2004-2006" "2000-2002")) ;define list

  (setq prefix (nth 0 saveoptions))
  (setq suffix (nth 1 saveoptions))
  (setq version (nth 2 saveoptions))
    (if (/= version "")
        (setq version (rtos (vl-position version FILEVERSIONS) ))
    )
  (setq path (nth 3 saveoptions))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  create DCL pop up box   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (if
    (and
      (setq saveoption (strcat (getvar "TEMPPREFIX") "saveoption.dcl")) ;;rename DCL file as necessary
      (setq des (open saveoption "w"))
      (foreach x
        '(
"         pass : dialog { key = \"DialogueKey\";  label = \"Save Options\"; " 
"           spacer;"

"  : boxed_row {label = \"File Name\"; alignment = top; width = 40; "
"    : column { label = \"\"; width = 17; "
"      : edit_box { key = \"Prefix\"; label = \"Prefix\"; width = 10; fixed_width = true;}"
"    }"
"    : column { label = \"\"; width = 7; alignment = centered; "
"      : text { key = \"File\"; label = \" [ - File - ] \";}"
"    }"
"    : column { label = \"\"; width = 16; "
"      : edit_box { key = \"Suffix\"; label = \"Suffix\"; width = 10; fixed_width = true;}"
"    }"
"  }"

"  : boxed_column { label = \"File Version and Location\";"
"  : row { alignment = top; width = 40; "
"    : text { key = \"version\"; label = \" Save As: \"; width = 8;}"
"    : popup_list {key = \"saveasversions\"; value = \"10\" ;}"
"    : text { key = \"Blank1\"; label = \"\"; width = 22;}"
"  }"

"  : row {alignment = top; width = 40; "
"    : button { key = \"folder\"; label = \"Save in:\"; is_default = false; fixed_width = true; width = 5;}"
"    : text { key = \"FilePath\"; label = \"Save in (File Path)\"; width = 35; fixed_width = true;}"
"  }"
"  }"

"  : boxed_row { label = \"\"; alignment = top; width = 40; "
"    : column { label = \"\"; width = 15; "
"      : button { key = \"OK\"; label = \"OK\"; is_default = true; is_cancel = true; fixed_width = true; width = 15; }"
"    }"

"    : column { label = \"\"; width = 15; "
"      : button { key = \"clear\"; label = \"Clear\"; is_default = false; fixed_width = true; width = 15; }"
"    }"

"    : column { label = \"\"; width = 15; "
"      : button { key = \"cancel\"; label = \"Clear and Cancel\"; is_default = false; is_cancel = true; fixed_width = true; width = 15; }"
"    }"
"  }"

"         }"               ;; End pass : dialog
        )                  ;; end '(
        (write-line x des)
      )                    ;;end foreach x
      (not (setq des (close des)))
      (< 0 (setq dch (load_dialog saveoption)))
      (new_dialog "pass" dch)
    )                      ;;End of DCL 'and'

    (progn

  (start_list "saveasversions")				  ;start the list box
  (mapcar 'add_list VERSIONS)				  ;fill the list box
  (end_list)						  ;end list


;;;;; Add Tile actions here ;;;;;;
      (set_tile "Prefix" prefix)
      (set_tile "Suffix" suffix)

      (if (/= version "")(set_tile "saveasversions" version ))
      (if (= version "") (set_tile "saveasversions" "0" ))

      (set_tile "FilePath" path)

      (action_tile "Prefix" "(setq prefix (get_tile \"Prefix\"))")
      (action_tile "Suffix" "(setq suffix (get_tile \"Suffix\"))")
      (action_tile "saveasversions" "(setq version (get_tile \"saveasversions\"))")

      (action_tile "folder" "(setq path (selectfolder path))(set_tile \"FilePath\" path)")
;;      (action_tile "FilePath" "(setq path (get_tile \"FilePath\"))")

      (action_tile "OK" "(setq prefix (get_tile \"Prefix\"))(setq suffix (get_tile \"Suffix\"))(done_dialog 1)")
      (action_tile "clear" "(setq prefix \"\")(setq suffix \"\")(setq version \"\")(setq path \"\")(set_tile \"Prefix\" \"\")(set_tile \"Suffix\" \"\")(set_tile \"saveasversions\" \"0\")(set_tile \"FilePath\" \"\")")
      (action_tile "cancel" "(setq prefix \"\")(setq suffix \"\")(setq version \"\")(setq path \"\")(done_dialog 0)")
;;;;;end tile actions here;;;;;

      (start_dialog)
    ) ;;end of DCL 'progn' above
    (princ "\nError. Unable to load dialogue box.")
  ) ;;end of DCL 'if' above
  (vl-file-delete saveoption) ;;delete the temp DCL file

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;    End DCL pop up box    ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Add rest of code here   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  (if (/= version "")(setq saveversion (nth (atoi version) FILEVERSIONS)))
  (if (= version "")(setq saveversion ""))

  (setq path (LM:StringSubst "\\\\" "\\" path))
  (setq path (strcat path "\\\\"))

  (setq saveoptions (list prefix suffix saveversion path))
  saveoptions

)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetDesktop ( / script spFolders desktop)
  (cond (
    (setq script (vlax-create-object "WScript.Shell"))
    (setq spFolders (vlax-get-property script "SpecialFolders")
          desktop   (vlax-invoke-method spFolders 'Item "Desktop")
    )
    (vlax-release-object spFolders)
    (vlax-release-object script)
    )
  )
  desktop
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun templspfile ( tempfolder / tempscrlisp tsl) ;;LSP routines for batchlisps. Saved as a temporary file
;;create temporary LSP file

 (setq tempscrlisp (strcat tempfolder "batchscrlisps.lsp"))
 (if (setq tsl (open tempscrlisp "w"))
   (progn
     (write-line "(vl-load-com)" tsl)

(write-line ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" tsl)

(write-line (strcat "(defun c:" "layout1() (layoutn 0) )") tsl)
(write-line (strcat "(defun c:" "layoutn(/ s)") tsl)
(write-line "  (IF (numberp (READ (setq s (getstring \"Enter Layout Number? \"))))" tsl)
(write-line "    (setq s (atoi s))" tsl)
(write-line "    (setq s 0)" tsl)
(write-line "  )" tsl)
(write-line "  (layoutn s)" tsl)
(write-line ")" tsl)
(write-line "(defun layoutn( n / nooflayouts)" tsl)
(write-line "  (if (< (length (layoutlist)) n)(setq n (length (layoutlist))) )" tsl)
(write-line "  (if (= 0 n)(setq n 1))" tsl)
(write-line "  (setvar \"ctab\" (nth (- n 1) (layoutlist)))" tsl)
(write-line "  (princ)" tsl)
(write-line ")" tsl)

(write-line "" tsl)
(write-line ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" tsl)
(write-line "" tsl)

(write-line "(defun LM:dwgversion ( fn / fd vr )" tsl)
(write-line "    (cond" tsl)
(write-line "        (   (null" tsl)
(write-line "                (and" tsl)
(write-line "                    (setq fn (findfile fn))" tsl)
(write-line "                    (setq fd (open fn \"r\"))" tsl)
(write-line "                )" tsl)
(write-line "            )" tsl)
(write-line "        )" tsl)
(write-line "        (   (wcmatch (strcase fn t) \"*`.dw[gst]\")" tsl)
(write-line "            (setq vr (strcase (substr (read-line fd) 1 6)))" tsl)
(write-line "        )" tsl)
(write-line "        (   (wcmatch (strcase fn t) \"*`.dxf\")" tsl)
(write-line "            (repeat 7 (read-line fd))" tsl)
(write-line "            (setq vr (strcase (read-line fd)))" tsl)
(write-line "        )" tsl)
(write-line "    )" tsl)
(write-line "    (if (= 'file (type fd)) (close fd))" tsl)
(write-line "    (cdr" tsl)
(write-line "        (assoc vr" tsl)
(write-line "           '(" tsl)
(write-line "                (\"AC1032\" . \"2018\")" tsl)
(write-line "                (\"AC1027\" . \"2013-2015\")" tsl)
(write-line "                (\"AC1024\" . \"2010-2012\")" tsl)
(write-line "                (\"AC1021\" . \"2007-2009\")" tsl)
(write-line "                (\"AC1018\" . \"2004-2006\")" tsl)
(write-line "                (\"AC1015\" . \"2000-2002\")" tsl)
(write-line "                (\"AC1014\" . \"Release 14\")" tsl)
(write-line "                (\"AC1012\" . \"Release 13\")" tsl)
(write-line "                (\"AC1009\" . \"Release 11/12\")" tsl)
(write-line "                (\"AC1006\" . \"Release 10\")" tsl)
(write-line "                (\"AC1004\" . \"Release 9\")" tsl)
(write-line "                (\"AC1003\" . \"Release 2.60\")" tsl)
(write-line "                (\"AC1002\" . \"Release 2.50\")" tsl)
(write-line "                (\"AC1001\" . \"Release 2.22\")" tsl)
(write-line "                (\"AC2.22\" . \"Release 2.22\")" tsl)
(write-line "                (\"AC2.21\" . \"Release 2.21\")" tsl)
(write-line "                (\"AC2.10\" . \"Release 2.10\")" tsl)
(write-line "                (\"AC1.50\" . \"Release 2.05\")" tsl)
(write-line "                (\"AC1.40\" . \"Release 1.40\")" tsl)
(write-line "                (\"AC1.2\"  . \"Release 1.2\")" tsl)
(write-line "                (\"MC0.0\"  . \"Release 1.0\")" tsl)
(write-line "            )" tsl)
(write-line "        )" tsl)
(write-line "    )" tsl)
(write-line ")" tsl)

(write-line "" tsl)
(write-line ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" tsl)
(write-line "" tsl)

(write-line (strcat "(defun c:" "batchsaveas (pre suf ver pth / dwgname currentversion saveasversion old)") tsl)
(write-line "  (setq vars '(\"CMDECHO\" \"FILEDIA\"))" tsl)
(write-line "  (setq old (mapcar 'getvar vars))" tsl)
(write-line "  (mapcar 'setvar vars '(0 0))" tsl)

(write-line "  (if (= 1 (getvar \"dwgtitled\"))" tsl)
(write-line "    (progn" tsl)

(write-line "      (setq dwgprefix (getvar \"dwgprefix\"))" tsl)
(write-line "      (if (/= pth \"\")(setq dwgprefix pth))" tsl)
(write-line "      (setq dwgname (strcat pre (vl-filename-base (getvar \"dwgname\")) suf \".dwg\" ))" tsl)
(write-line "      (setq str (strcat dwgprefix dwgname ))" tsl)

;;(write-line "    (setq str (strcat (getvar \"dwgprefix\") dwgname ))" tsl)
;;(write-line "    (setq str (strcat (getvar \"dwgprefix\")(getvar \"dwgname\")))" tsl)

(write-line "      (setq thisdrawing (vla-get-ActiveDocument (vlax-get-acad-object)))" tsl)
(write-line "      (setq currentversion (LM:dwgversion (strcat (getvar 'dwgprefix) (getvar 'dwgname))))" tsl)
(write-line "      (if (/= ver \"\")(setq currentversion ver))" tsl)

(write-line "      (cond" tsl)
(write-line "        ((= currentversion \"2018\")(vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2018_dwg))" tsl)
(write-line "        ((= currentversion \"2013-2015\")(vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2013_dwg))" tsl)
(write-line "        ((= currentversion \"2010-2012\")(vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2010_dwg))" tsl)
;;(write-line "        ((= currentversion \"2007-2009\")(vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2007_dwg))" ;;tsl)
;;(write-line "        ((= currentversion \"2004-2006\")(vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2004_dwg))" ;;tsl)
;;(write-line "        ((= currentversion \"2000-2002\")(vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2004_dwg))" ;;tsl)
(write-line "        (T (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2018_dwg))" tsl)


(write-line "    )" tsl)
(write-line "  )" tsl)
(write-line "  (if (= 0 (getvar \"dwgtitled\")) (COMMAND \"_.saveas\" \"\" \"~\") )" tsl)
(write-line "  (mapcar 'setvar vars old)" tsl)
(write-line "  (princ)" tsl)
(write-line ")" tsl)
(write-line ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" tsl)

;;close routine
(write-line (strcat "(defun c:" "batchclose( / )") tsl)
(write-line (strcat "  (if (= dbmod 0)(command \".close\"))") tsl)
(write-line (strcat "  (if (/= dbmod 0)(command \".close\" \"y\"))") tsl)
(write-line (strcat ")") tsl)

      (close tsl) ;; Close file descriptor
    ) ;; end PROGN
    (princ "\nUnable to create temp LISP file.") ;; Else the text file could not be created
  ) ;; end IF
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;-- end reference routines ---;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                          ;;
;;                                                          ;;
;; MAIN PROGRAM                                             ;;
;;                                                          ;;
;;                                                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;This works by opening each drawing individually, processing the script that is developed via the pop-up boxes
;;saving then closing the drawing (as required). This is not the fastest method to process a script, there are programmes
;;that will process a script without the need to open each drawing individually. However... by opening each
;;drawing a backup file (*.bak) is created when its saved... which can be used as an basic 'undo' option
;;Most script editors can't undo a change that they make.

(defun c:batchlisps ( / PreselectedList )
  (setq PreselectedList "")
  (batchlisps PreselectedList)
)


(defun batchlisps( PreselectedList / saveoptions version batchdirectory batchfiletype batchsubdirectory removedfilelist KeepFileList lsp-command tempfolder fixedtempfolder mylispfolder dcl des x dch butttext batchprocessing DrLi FileName currentdrawing activedrawing ClosedFiles OpenedFiles tempscript f acount currentdocname n)

;;(defun batchlisps( PreselectedList / dcl des dch saveoptions plussave plusopen plusclose prefix suffix saveversion version ;;batchdirectory batchsubdirectory batchfiletype)
;(defun c:batchlisps( / dcl des dch saveoptions plussave plusopen plusclose prefix suffix saveversion version batchdirectory ;batchsubdirectory batchfiletype)

  (resetDCLfiles)

;;Initial values
  (setq plussave 1) ;;remember to change check box initial value
  (setq plusopen 1) ;;remember to change check box initial value
  (setq plusclose 1) ;;remember to change check box initial value

  (setq saveoptions (list "" "" "" ""))
  (setq version "")
  (setq batchdirectory (getvar "dwgprefix"))

  (setq batchfiletype "*.dwg")

  (setq batchsubdirectory 0) ;;default only searches parent directory
  (setq removedfilelist nil)
  (setq KeepFileList nil)

  (SP:batchfileslist 0 batchfiletype) ;;get list of files in drawing folder
  (setq lsp-command "")
  (setq tempfolder (getvar "TEMPPREFIX") ) ;;temporary files location

  (setq fixedtempfolder (LM:StringSubst "\\\\" "\\" tempfolder))
  (setq mylispfolder (strcat (getdesktop) "\\AutoCAD\\AutoCAD LISPS\\"))
  (if (not (vl-file-directory-p mylispfolder))(setq mylispfolder "C:\\")) ;; if folder above doesn't exist

;;create DCL pop up box
  (if
    (and
      (setq dcl (strcat (getvar "TEMPPREFIX") "BatchLisps.dcl"))
      (setq des (open dcl "w"))
      (foreach x
        '(

"  pass : dialog"
"  {"
"    key = \"Batchdialoguebox\";"
"    label = \"Batch routines\";"

"    :boxed_column { label = \"Enter Commands in order, then press 'Add'\"; width = 50;"

"      :row {alignment = top; width = 50;"
"        :column { width = 8;"
"          : text { key = \"SpecifyCommand\"; label = \"Command\"; width = 5; alignment = left;}"
"        }"
"        :column { width = 26;"
"          : edit_box { key = \"TypeCommand\"; width = 25; fixed_width = true;}"
"        }"
"        :column { width = 16;"
"          : row {"
"            : column { width = 2;"
"              : button { key = \"FindLisp\"; label = \"Find\"; is_default = false; fixed_width = true; width = 2; }"
"            }"
"            :column { width = 8;"
"              : button { key = \"AddCOMMAND\"; label = \">> Add\"; is_default = false; fixed_width = true; width = 8; }"
"            }"
"            :column { width = 6;"
"            }"
"          }"
"        }"
"      }"

"      :row {alignment = top; width = 50;"
"       :column { width = 8;"
"         : text { key = \"lisplibrary\"; label = \"Lisp Library\"; width = 5;}"
"        }"
"        :column { width = 26;"
"          : text { key = \"foldertext\"; label = \"Lisp Library\"; width = 40;}"
"        }"
"        :column { width = 16;"
"          : row {"
"            :column { width = 8;"
"            }"
"            :column { width = 8;"
"            }"
"          }"
"        }"
"      }"

"      :row {alignment = top; width = 50;"
"        :column { width = 6;"
"        }"
"        :column { width = 26;"
"          : button { key = \"lispfolder\"; label = \"Change Lisp Library\"; is_default = false; fixed_width = true; width = 25;}"
"        }"
"        :column { width = 16;"
"          : row {"
"            :column { width = 8;"
"            }"
"            :column { width = 8;"
"            }"
"          }"
"        }"
"      }"

"      :row {alignment = top; width = 50;"
"        :column { width = 8;"
"          : text { key = \"addSCRIPTtext\"; label = \"Add Script\"; width = 5; alignment = left;}"
"        }"
"        :column { width = 26;"
"          : edit_box { key = \"scriptname\"; width = 25; fixed_width = true;}"
"        }"
"        :column { width = 16;"
"          : row {"
"            : column { width = 2;"
"              : button { key = \"FindScript\"; label = \"Find\"; is_default = false; fixed_width = true; width = 2; }"
"            }"
"            :column { width = 8;"
"              : button { key = \"AddSCRIPT\"; label = \">> Add\"; is_default = false; fixed_width = true; width = 8; }"
"            }"
"            :column { width = 6;"
"            }"
"          }"
"        }"
"      }"
"    }" ;;end boxed column

;;;;;;;;;;;;;select command section end;;;;;;;;;;;;;;;

"         :boxed_column { label = \"Commands List\"; width = 50;"
"          :row {alignment = top; width = 50;"
"            : column { width = 15;"
"              :row {alignment = top;"
"                : text { key = \"openthem\"; label = \"Open:\"; alignment = left;}"
"              }"
"              :row {alignment = top;"
"                : text { key = \"andthen\"; label = \"and then:\"; alignment = left;}"
"              }"
"            }"
"            : column { width = 20;"
"              :row {alignment = top;"
"                : toggle {key = \"plusopentoggle\"; label = \"+ DWGs\"; alignment = left; value = 1;}"
"                : text { key = \"futureoptions\"; label = \"FUTURE + DWG / DXF OPTION\"; alignment = left;}"
"              }"
"              :row {alignment = top;"
"                : text { key = \"clicktoedit\"; label = \"(click to edit)\"; alignment = left;}"
"              }"
"            }"
"            : column { width = 15;"
"              :row {alignment = top;"
;"                : text { key = \"futureoptions\"; label = \"FUTURE TO ADD DWG / DXF OPTION\"; alignment = left;}"
"              }"
"              :row {alignment = top;"
"              }"
"            }"
"          }"

"           :row {width = 50;"
"             :row {alignment = top;"
"               :column {width = 38;"
"                 :row {alignment = top;"
"                   : list_box {key = \"SCRIPTTEXT\"; height = 12; fixed_height = true; width = 38; }"
"                 }"
"               }"
"              : boxed_column {width = 12; fixed_height = true; height = 6;"
"              : button { key = \"ClearLISP\"; label = \"Clear List\"; is_default = false; fixed_width = true; width = 14; }"
"              : button { key = \"SaveSCR\"; label = \"Save Script\"; is_default = false; fixed_width = true; width = 14; }"
"              : button { key = \"LoadSCR\"; label = \"Load Script\"; is_default = false; fixed_width = true; width = 14; }"
"              : button { key = \"LoadLast\"; label = \"Load Last\"; is_default = false; fixed_width = true; width = 14; }"
"              : text { key = \"blanktext1\"; label = \"\"; alignment = left;}"
"              }"
"            }"
"          }"

"          :column {width = 50;"
"            :row {alignment = top;"
"              :column {width = 15;"
"                :row {alignment = top; height = 1.1;"
"                  : text { key = \"scriptadds\"; label = \"and then:\"; alignment = left;}"
"                }"
"                :row {alignment = top; height = 1.1;"
"                }"
"                :row {alignment = top; height = 1.1;"
"                  : text { key = \"eachfile\"; label = \"files in this folder:\"; alignment = left;}"
"                }"
"              }"
"              :column {width = 20;"
"                :row {alignment = top; height = 1.1;"
"                  : toggle {key = \"plussavetoggle\"; label = \"+ SAVE\"; alignment = left; value = 1;}"
"                }"
"                :row {alignment = top; height = 1.1;"
"                  : toggle {key = \"plusclosetoggle\"; label = \"+ CLOSE\"; alignment = left; value = 1;}"
"                }"
"                :row {alignment = top; height = 1.1;"
"                  : toggle { label = \"+ Sub-Folders\"; width = 10; key = \"Toggle1\"; }"
"                }"
"              }"
"              :column {width = 15;"
"                :row {alignment = top; height = 1.1;"
"                  : button { key = \"SaveOptions\"; label = \"Save Options\"; is_default = false; fixed_width = true; width = 14; }"
"                }"
"                :row {alignment = top; height = 1.1;"
"                }"
"                :row {alignment = top; height = 1.1;"
"                  : button { key = \"Folder\"; label = \"Change Folder\"; is_default = false; fixed_width = true; width = 14; }"
"                }"
"              }"
"          }"

"          : column {width = 50;"
"            : row {alignment = top;"
"              : text {key = \"FolderLocation1\"; label = \"File Location\"; }"
"            }"
"            : row {alignment = top;"
"              : text {key = \"FolderLocation2\"; label = \"\"; }"
"            }"
"          }"

"          :column {width = 50;"
"            :row {alignment = top;"
"              :column {width = 15;"
"                spacer;"
"              }"
"              :column {width = 20;"
"                :row {alignment = top;"
"                }"
"              }"
"              :column {width = 15;"
"                :row {alignment = top;"
"                  : button { key = \"EditFileList\"; label = \"Edit File List\"; is_default = false; fixed_width = true; width = 14; }"
"                }"
"              }"
"            }"
"          }"
"        }"
"      }"

"        :boxed_column { label = \"\"; width = 50;"
"          :row {alignment = top;"
"            : button { key = \"batch\"; label = \"Run Batch\"; is_default = false; is_cancel = true; fixed_width = true; width = 14; }"
"            : button { key = \"thisfile\"; label = \"Run on this drawing only\"; is_default = false; is_cancel = true; fixed_width = true; width = 14; }"
"            : button { key = \"cancel\"; label = \"Cancel\"; is_default = false; is_cancel = true; fixed_width = true; width = 14; }"
"          }"
"        }"

"        : row {alignment = top;"
"          : text {key = \"note1\"; label = \"Notes:\"; width = 40; fixed_width = true;}"
"        }"
"        :row {alignment = top; width = 50;"
"          : text { key = \"note2\"; label = \"Add a blank line to escape from a command (example to end a series of line coordinates)\"; }"
"        }"
"        : row {alignment = top;"
"          : text {key = \"note3\"; label = \"Blank lines in the script act like a space or return character in the command line\"; width = 40; fixed_width = true;}"
"        }"
"        : row {alignment = top;"
"          : text {key = \"note4\"; label = \"This will only process the closed files or this open file, other opened files will be ignored\"; width = 40; fixed_width = true;}"
"        }"
"        : row {alignment = top;"
"          : text {key = \"note5\"; label = \"\"; width = 40; fixed_width = true;}"
"        }"
"      }"

        )
        (write-line x des)
      )
      (not (setq des (close des)))
      (< 0 (setq dch (load_dialog dcl)))
      (new_dialog "pass" dch)
    )  ;;end of DCL 'and' above
;;End of DCL pop up box description

;;DCL Controls and buttons
    (progn
      (mode_tile "TypeCommand" 2) ;;set focus to TypeCommand
      (setq batchdirectory (getvar "dwgprefix")) ;;drawing current directory as default location

      (set_tile "FolderLocation1" (strcat (substr batchdirectory 1 74) "..."))
      (if (<= 75 (strlen batchdirectory)) (set_tile "FolderLocation2" (strcat "..." (substr batchdirectory 75 150))))

      (set_tile "foldertext" mylispfolder)
      (SP:BatchLispList mylispfolder) ;;get list of lisps and populate DCL box list  ;;----;;
      (start_list "BatchAllLisps" 3)(mapcar 'add_list allthelisps)(end_list);;create Lisp files list
      (action_tile "AddCOMMAND" "(setq CommandOK (AddCommands (get_tile \"TypeCommand\") (vl-list-length (lm:str->lst lsp-command \"\\n\")))))")

      (setq butttext (list "NA" "Select Lisp" "Cancel" "NA")) ;;lisp help buttons
      (action_tile "FindLisp" "(setq result (lisphelp butttext mylispfolder ))(if (= (nth 0 result) \"butt1\")(set_tile \"TypeCommand\" (nth 2 result))(set_tile \"foldertext\" (nth 5 result))) ")


      (action_tile "BatchAllLisps" "(set_tile \"TypeCommand\" (nth (atoi (get_tile \"BatchAllLisps\")) allthelisps))")

      (action_tile "lispfolder" "(setq blf (SP:batchlispfolder))(setq mylispfolder (nth 0 blf))(setq runlispfiles (nth 1 blf))(set_tile \"foldertext\" mylispfolder)(setq allthelisps (nth 2 blf))")
      (action_tile "SCRIPTTEXT" "(SP:clickedon (get_tile \"SCRIPTTEXT\"))")
      (action_tile "FindScript" "(SP:FindScript)")

      (action_tile "AddSCRIPT" "(setq CommandOK (AddCommands (get_tile \"scriptname\") (vl-list-length (lm:str->lst lsp-command \"\\n\")))))")
      (action_tile "SelectScript" "(SP:AddScript)")
      (action_tile "ClearLISP" "(SP:ClearLisps)")

      (action_tile "SaveSCR" "(savescript lsp-command)")
      (action_tile "LoadSCR" "(loadscript)")
      (action_tile "LoadLast" "(loadlastscr)")

      (action_tile "SaveOptions" "(setq saveoptions (saveoptionsscr saveoptions))")
      (action_tile "Folder" "(SP:ChangeFolder)(SP:batchfileslist (read (get_tile \"Toggle1\")) batchfiletype)")
      (action_tile "EditFileList" "(SP:Editfileslist)")

      (action_tile "plusopentoggle" "(setq plusopen (read (get_tile \"plusopentoggle\")))")
      (action_tile "plussavetoggle" "(setq plussave (read (get_tile \"plussavetoggle\")))")
      (action_tile "plusclosetoggle" "(setq plusclose (read (get_tile \"plusclosetoggle\")))")

      (action_tile "Toggle1" "(SP:batchfileslist (read (get_tile \"Toggle1\")) batchfiletype)")
      (action_tile "thisfile" "(setq ifcancel \"No\")(setq plusopen 0)(done_dialog)")
      (action_tile "batch" "(setq ifcancel \"No\") (done_dialog)")

      (action_tile "cancel" "(setq ifcancel \"Yes\") (done_dialog)")

      (start_dialog)
    ) ;;end ofprogn above DCL controls
    (princ "\nError. Unable to load dialogue box.")
  ) ;;end of DCL 'if' above
  (vl-file-delete dcl) ;;delete the temp DCL file
;;end of DCL definition



;;save script to temp file
  (if (<= 1 (strlen lsp-command)) (savescripta (strcat (getvar "TEMPPREFIX") "tempbatchscrpt.scr") lsp-command) )
  (if (= 0 (strlen lsp-command)) 
    (progn
      (if (findfile (strcat (getvar "TEMPPREFIX") "tempbatchscrpt.scr"))
      (vl-file-delete (strcat (getvar "TEMPPREFIX") "tempbatchscrpt.scr"))
    )
  )
  (savescripta (strcat (getvar "TEMPPREFIX") "tempbatchscrpt.scr") lsp-command)) ;;save script to temp file

  (if (= ifcancel "No")
    (progn
      (setq batchprocessing "Yes")

;;create temporary LSP file
        (templspfile  tempfolder)


;;Get open drawings and closed drawings list
      (setq DrLi nil) ;;clear drawing list
      (vlax-for IAcadDoc (vla-get-documents (vlax-get-acad-object ) )
        (setq DrLi (cons (if (/= (setq FileName (vla-get-fullname IAcadDoc )) "" ) FileName (vla-get-name IAcadDoc ) ) DrLi ) )
      )

;; Get Current Drawing
      (setq currentdrawing (strcat (getvar "dwgprefix")(getvar "dwgname")))
      (setq activedrawing (vl-position currentdrawing (reverse DrLi)) )
      (if (= activedrawing nil)(setq activedrawing 0))
      (setq currentdrawing (strcat (getvar "dwgprefix")(getvar "dwgname")))

;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/compare-two-lists/td-p/3575124
;;Closed Files List
      (setq ClosedFiles nil)
      (if (< (length batchfileslist) (length DrLi))
        (mapcar (function (lambda (x) (if (not (member x batchfileslist))(setq ClosedFiles (cons x ClosedFiles)))))
          DrLi
        )
        (mapcar (function (lambda (x) (if (not (member x DrLi))(setq ClosedFiles (cons x ClosedFiles)))))
          batchfileslist
        )
      )

;;Add in here check if file is opened or not
;;If opened create a report file in the temp folder to be opened after the routine
;;if not keep in list
;;See PlotPDF for file check
;;then put OK list in 'ClosedFiles' list


;;  Open Files List
      (setq OpenedFiles nil)
      (if (< (length grabbedfiles) (length DrLi))
        (mapcar (function (lambda (x) (if (member x batchfileslist)(setq OpenedFiles (cons x OpenedFiles)))))
          DrLi
        )
        (mapcar (function (lambda (x) (if (member x DrLi)(setq OpenedFiles (cons x OpenedFiles)))))
          batchfileslist
        )
      )

      (setq ClosedFiles (reverse ClosedFiles))
      (setq OpenedFiles (reverse OpenedFiles))


;;Create and open script file
      (if (not (strcat (getvar "TEMPPREFIX") "myscr.scr")) (princ "no SCR file"))
      (setq tempscript (strcat (getvar "TEMPPREFIX") "myscr.scr")) ;;add check if this exists
      (setq f (open tempscript "w")) ;;open file
      (setq acount 0) ;; a counter
      (if (<= 1 (strlen lsp-command)) ;;if there are any commands write script
        (progn

;;Write script for current file
      (if (member currentdrawing OpenedFiles)
        (progn
          (setq OpenedFiles (vl-remove currentdrawing OpenedFiles)) ;;remove current drawing from the list

          (write-line (strcat "(load \"" fixedtempfolder "\batchscrlisps.lsp\")") f) ;;load tmp LISP file
          (write-line lsp-command f) ;;do commands

          (if (= plussave 1)
            (progn
              (write-line (strcat "(c:batchsaveas  \""(nth 0 saveoptions)"\" \""(nth 1 saveoptions)"\" \""(nth 2 saveoptions)"\" \""(nth 3 saveoptions)"\")") f) ;;run batchsaveas lisp
          )) ;;end if plussave
        ) ;;end progn current drawing
      ) ;;end if current drawing



;;write script for all opened drawings
;;;;(setq ss (vla-get-activedocument (vlax-get-acad-object))) ;;set ss as the current drawing
;;;;(vl-propagate 'ss)
;;;;          (setq acount 0) ;; a counter
;;;          (setq currntdrawingname (cadr (fnsplitl currentdrawing)))
;;;;          (foreach n OpenedFiles ;;these don't need to be saved or closed just here, user can decide that
;;;;            (progn
;;;;write commands
;;;;              (write-line lsp-command f) ;;do commands
;;;;(write-line (strcat "(vla-put-activedocument (vlax-get-acad-object) " ss ")") f)
;;;;              (write-line lsp-command f) ;;do commands
;;;;              (setq acount (+ 1 acount))
;;;;            ) ;;end progn
;;;;          ) ;;end for each opened files



(setq currentdocname nil)

;;Write script for closed drawings
(setq acount 0) ;; a counter
(if (= plusopen 1)
  (progn
    (foreach n ClosedFiles
      (progn
        (write-line (strcat "_.OPEN \"" (nth acount ClosedFiles) "\"") f) ;;open drawing

        (if (= plusclose 1) ;;close the files... done this way to acount for saved or not saved file
          (progn
            (if (/= currentdocname nil)
(write-line (strcat "(vla-close (vla-item (vla-get-documents (vlax-get-acad-object)) \""currentdocname"\") :vlax-false)") f)
           )
          ) ;end progn
        ) ;end if plusclose
(setq currentdocname (strcat (VL-FILENAME-BASE (nth acount ClosedFiles)) ".dwg"))

        (write-line (strcat "(load \"" fixedtempfolder "\batchscrlisps.lsp\")") f) ;;load tmp LISP file
        (write-line lsp-command f) ;;do commands   ;;write commands to script file, change to write script file link to file

        (if (= plussave 1)
          (write-line (strcat "(c:batchsaveas  \""(nth 0 saveoptions)"\" \""(nth 1 saveoptions)"\" \""(nth 2 saveoptions)"\" \""(nth 3 saveoptions)"\")") f) ;;run batchsaveas lisp
        ) ;;Save drawing

      (setq acount (+ 1 acount))
      ) ;;end progn
    ) ;;end for each closed files

    (if (= plusclose 1) ;;Close file after next file is opened
      (progn
        (write-line (strcat "(vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) \"(c:batchclose)\r\")") f)
      ) ;end progn
    ) ;end if plusclose

  ) ;end plus open progn
) ;end plus open
        )

      ) ;;end script definition
      (close f)

;;Run the script
      (command "_.SCRIPT" tempscript) ;;run script

      (setq batchprocessing "No")

    ) ;end progn
  ) ;end if
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                          ;;
;;                                                          ;;
;; END OF MAIN PROGRAM                                      ;;
;;                                                          ;;
;;                                                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;












;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun AddCommands(lspcommand AddPosition / CommandOK) ;;add commands to a string
  (setq lspcommand (vl-string-left-trim " " lspcommand)) ;;strips leading spaces

  (if (= "Script" (nth 0 (LM:str->lst lspcommand "::")))
    (progn
      (loadscripta Chosenscriptpath "Append")
      (set_tile "TypeCommand" "") ;;empty edit box
    )
  )

  (if (/= "Script" (nth 0 (LM:str->lst lspcommand "::")))
  (progn
    (setq commandOK (SP:commandcheck lspcommand allthelisps))
    (if (/= "lisp" commandOK) ;;if you only want to use single line of commands
      (progn
        (if (= "OK" commandOK) (setq lspcommand (strcase lspcommand)) ) ;;Set upper case / lower case in script lisitng
        (if (/= "" lsp-command)(setq lsp-command (strcat lsp-command "\n"))) ;;new line between commands
        (if (= AddPosition 1)
          (if (= (vl-list-length (lm:str->lst lsp-command "\n")) 1)(setq AddPosition 0))
        )
;;Add LISP command to script
        (setq lsp-commandList (LM:str->lst lsp-command "\n"))
        (setq lsp-commandList (replace-n lspcommand AddPosition lsp-commandlist))
        (setq lsp-command (LM:lst->str lsp-commandList "\n"))
        (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (lm:str->lst lsp-command "\n"))(end_list) ;;display commands list
        (set_tile "TypeCommand" "") ;;empty edit box
        (mode_tile "TypeCommand" 2) ;;put curser focus into edit box
      )
    )
    (if (= "lisp" commandOK)
      (progn
        (AddLisps (itoa myposition) (vl-list-length (lm:str->lst lsp-command "\n")))
      );; endprogn
    )
  )
  )
  CommandOK
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:commandcheck(mycommand allthelisps / commandOK) ;;works but.... can't handle for example 'all' in "ZOOM ALL". Can also use 'command-s'
  (setq mycommandlist (LM:Str->lst mycommand " ")) ;; Command line to a list
  (setq mycommand (nth 0 mycommandlist)) ;; get first word of list
  (if (= nil (getcname mycommand)) ;; if 1st word of mycommand not a command
    (progn
      (setq commandOK "error")
      (setq myposition (vl-position (strcase mycommand) allthelisps))

      (if (/= nil myposition)
        (progn
          (setq commandOK "lisp")
        )
      )
      (if (= nil myposition)
        (progn
          (setq commandOK "error")
          (alert "Invalid command (but might be a valid input), please check.")
        )
      )
    )
  )
  (if (/= nil (getcname mycommand))(setq commandOK "OK"))
  commandOK
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:BatchLispList ( lisplistfolder / SortedLisps SortedFiles SortedListLength SortedCount) ;;this bit causes problems sometimes

  (setq allthelisps nil)
  (setq mylispfileslist nil)
  (setq mylispfileslist "")

  (setq mylispfiles (vl-directory-files lisplistfolder "*.lsp" nil)) ;;mylispfiles is list of files in mylispfolder location
  (setq mylistlength (length mylispfiles)) ;;count of number of lsp files
  (setq acount -1)

  (setq myroutines "")

  (repeat mylistlength
    (setq acount (1+ acount))
    (setq myfilename (strcat lisplistfolder (nth acount mylispfiles)))

    (progn
      (if (not (mapcar '(lambda ( x ) (princ)) (setq mylisplist (LM:GetSyntax myfilename)))) ;;puts list into an array
        (princ "\n -None-\n")
      )

      (setq mylisplist (vl-remove "\"" mylisplist)) ;;to remove defined items from the array.
      (foreach n mylisplist                         ;;loops through array
        (progn
          (setq allthelisps (cons n allthelisps))         ;;All the lisps is a list of all the lisps
          (setq mylispfileslist (cons myfilename mylispfileslist)) ;;generates a list of files coresponding to the LISPS
        )
      )
    )
  )

  (setq SortedLisps (vl-sort allthelisps '<)) ;;sorts the list
  (setq SortedListLength (vl-list-length SortedLisps))
  (setq SortedCount 0)

;;Sorts the lisp files list
  (while (<= (1+ SortedCount) (vl-list-length SortedLisps))
    (setq LLFilePath (nth (vl-position (nth SortedCount SortedLisps) allthelisps) mylispfileslist)) ;;make into a list
    (setq SortedFiles (cons LLFilePath SortedFiles)) ;;generates a list of files coresponding to the LISPS
    (setq SortedCount (1+ SortedCount))
  )
  (setq allthelisps SortedLisps)
  (setq mylispfileslist (reverse SortedFiles))
  allthelisps
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun AddLisps(mylisp LispPosition) ;;my lisp as position

  (setq mylispfile (nth (read mylisp) mylispfileslist))
  (setq mylisp (nth (read mylisp) allthelisps))
  (setq mylisp (strcase mylisp))

  (if (= LispPosition (vl-list-length (lm:str->lst lsp-command "\n"))) ;;add blank line to end of list if a new command
    (if (/= "" lsp-command)(setq lsp-command (strcat lsp-command "\n"))) ;;new line between commands
  )

  (if (= LispPosition 1)
      (if (= (vl-list-length (lm:str->lst lsp-command "\n")) 1)(setq LispPosition 0))
  )

;;Add LISP command to script
  (setq lsp-commandList (LM:str->lst lsp-command "\n"))
  (setq lsp-commandList (replace-n mylisp LispPosition lsp-commandlist))
  (setq lsp-command (LM:lst->str lsp-commandList "\n"))

;;Add Load LISP File to script
  (setq loadlisp (strcase (strcat "load \"" mylispfile "\"")))
  (setq LispPosition (+ 1 LispPosition))
  (setq list-lsp-command (lm:str->lst lsp-command "\n"))

  (setq list-lsp-command (inslistabove loadlisp LispPosition list-lsp-command))
  (setq lsp-command (lm:lst->str list-lsp-command "\n"))

  (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (lm:str->lst lsp-command "\n"))(end_list) ;;display commands list
  (set_tile "TypeCommand" "") ;;empty edit box
  (mode_tile "TypeCommand" 2) ;;put curser focus into edit box

)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:batchlispfolder( / blfMyDir blfLispFiles lispfiles lispfolder allthelispsa)


;;;UP TO HERE;;



  (setq blfMyDir (LM:browseforfolder "Select a folder" "blfMyDir" 0))
  (if (/= blfMyDir Nil) ;;if folder selection wasn't cancelled
    (progn
      (set_tile "foldertext" blfMyDir)
      (setq blfMyDir (strcat blfMyDir "\\"))
      (setq blfLispFiles (vl-directory-files blfMyDir "*.lsp" nil)) ;;runlispfiles is the list of files in runlispdir location

;;      (start_list "lispfiles" 3)(mapcar 'add_list blfLispFiles)(end_list) ;;create Lisp files list
      (setq allthelispsa (SP:BatchLispList blfMyDir))

      (start_list "BatchAllLisps" 3)(mapcar 'add_list allthelispsa)(end_list);;create Lisp files list
    );;end progn
  );; end if
  (list blfMyDir blfLispFiles allthelispsa)





)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:clickedon(LisptoEdit) ;; when a script item is selected
;;create Edit Options dcl pop up box
  (if
    (and
      (setq EditOptionsdcl (strcat (getvar "TEMPPREFIX") "EditOptionsScript.dcl"))
      (setq EditOptionsdes (open EditOptionsdcl "w"))
      (foreach z
        '(
"       EditOptionspass : dialog"
"       {"
"         key = \"EditOptionsDialogue\";"
"         label = \"Script Line\";"
"         :boxed_column { label = \"Edit Line\"; width = 50;"
"           :row {alignment = top; width = 20;"
"             : text {key = \"Options1\"; label = \"Do you want to:\"; width = 40; fixed_width = true;}"
"           }"
"           :row {alignment = top; width = 50;"
"             :column { label = \"\"; width = 20;"
"               :row {alignment = top; width = 20;"
"                 : button { key = \"EditLine\"; label = \"Edit Command\"; is_cancel = false; width = 15;}"
"               }"
"               :row {alignment = top; width = 20;"
"                 : button { key = \"DeleteLine\"; label = \"Delete Command\"; is_cancel = false; width = 15;}"
"               }"
"             }"
"             :column { label = \"\"; width = 20;"
"               :row {alignment = top; width = 20;"
"                 : button { key = \"AddLineAbove\"; label = \"Add Command Above\"; is_cancel = false; width = 15;}"
"               }"
"               :row {alignment = top; width = 20;"
"                 : button { key = \"AddLineBelow\"; label = \"Add Command Below\"; is_cancel = false; width = 15;}"
"               }"
"             }"
"          }"
"          :row {alignment = top; width = 50;"
"            : button { key = \"EditOptionsCancel\"; label = \"Cancel\"; is_cancel = true; width = 15;}"
"          }"
"        }"
"    }"

        )
        (write-line z EditOptionsdes)
      )
      (not (setq EditOptionsdes (close EditOptionsdes)))
      (< 0 (setq EditOptionsdch (load_dialog EditOptionsdcl)))
      (new_dialog "EditOptionspass" EditOptionsdch)
    ) ;;end of EditOptionsdcl 'and' above

    (progn
      (mode_tile "EditLine" 2) ;;focus to tile (0: Enable Tile, 1: Disable Tile, 2: set focus to tile, 3: Select edit box contents, 4: flip image highlighting on / off

      (action_tile "AddLineBelow" "(SP:addlinetolistBelow LisptoEdit)(done_dialog 0)")
      (action_tile "AddLineAbove" "(SP:addlinetolistAbove LisptoEdit)(done_dialog 0)")
      (action_tile "DeleteLine" "(SP:RemoveLisp LisptoEdit)(done_dialog 0)")
      (action_tile "EditLine" "(SP:editscriptline LisptoEdit)(done_dialog 0)")
      (action_tile "EditOptionsCancel" "(done_dialog 0)")

      (start_dialog)
    ) ;;end of editoptionsdcl 'progn' above
    (princ "\nError. Unable to load dialogue box.")
  ) ;;end of editoptionsdcl 'if' above
  (vl-file-delete EditOptionsdcl) ;;delete the temp editdcl file

  (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (lm:str->lst lsp-command "\n"))(end_list) ;;display commands list
  (mode_tile "TypeCommand" 2) ;;set focus to TypeCommand

)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:ClearLISPS()
  (setq lsp-command "")
  (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (lm:str->lst lsp-command "\n"))(end_list) ;;display commands list
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:RemoveLISP(Lisptodelete)
  (setq list-lsp-command (lm:str->lst lsp-command "\n"))
  (setq listlength (vl-list-length list-lsp-command))

  (if (>= 1 (vl-list-length list-lsp-command))(SP:ClearLISPS))
  (if (<= 2 (vl-list-length list-lsp-command))
    (progn
      (setq list-lsp-command (LM:RemoveNth (read Lisptodelete) list-lsp-command))
      (setq lsp-command (lm:lst->str list-lsp-command "\n"))
      (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (lm:str->lst lsp-command "\n"))(end_list) ;;display commands list
    )
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-insert-item-in-the-list-at-nth-index/td-p/2478116
(defun inslistabove (new pos lista / inc list1 list2)
  (setq inc 0 list1 lista)
  (while (< (1+ inc) pos)
    (setq
      list2 (append list2 (list (car list1)))
      list1 (cdr list1)
      inc (1+ inc)
    ); end setq
  ); end while
  (setq list2 (append list2 (cons new list1)))
  list2
); end defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:addlinetolistAbove(LineBelow)
  (setq pos (+ 1 (read LineBelow)))
  (setq list-lsp-command (lm:str->lst lsp-command "\n"))
  (setq list-lsp-command (inslistabove "" pos list-lsp-command))
  (setq lsp-command (lm:lst->str list-lsp-command "\n"))
  (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (lm:str->lst lsp-command "\n"))(end_list) ;;display commands list
  (SP:editscriptline LineBelow) ;;what to do if edit command cancels, it still has a line added

)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-insert-item-in-the-list-at-nth-index/td-p/2478116
(defun inslistbelow (new pos lista / inc list1 list2)
  (setq inc 0 list1 lista)
  (while (< inc pos)
    (setq
      list2 (append list2 (list (car list1)))
      list1 (cdr list1)
      inc (1+ inc)
    ); end setq
  ); end while
  (setq list2 (append list2 (cons new list1)))
  list2
); end defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:addlinetolistBelow(Lineabove)
  (setq pos (+ 1 (read Lineabove)))
  (setq list-lsp-command (lm:str->lst lsp-command "\n"))
  (setq list-lsp-command (inslistbelow "" pos list-lsp-command))
  (setq lsp-command (lm:lst->str list-lsp-command "\n"))
  (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (lm:str->lst lsp-command "\n"))(end_list) ;;display commands list
  (SP:editscriptline (itoa pos)) ;;what to do if edit command cancels this still adds a line
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:editscriptline(LisptoEdit / edittile lsp-commandlist)
;;create editdcl pop up box

(setq edittile "")

  (if
    (and
      (setq editdcl (strcat (getvar "TEMPPREFIX") "EditScript.dcl"))
      (setq editdes (open editdcl "w"))
      (foreach y
        '(
"       editpass : dialog"
"       {"
"         key = \"EditScriptDialogue\";"
"         label = \"Script Line\";"
"         :boxed_column {label = \"Ed Command\"; width = 50;"
"           :row {alignment = top;"
"             : edit_box { key = \"EditCommand\"; width = 40; fixed_width = true;}"
"           }"

"           :row {alignment = top; width = 50;"
"             :column { width = 8;"
"               : text { key = \"SpecifyLISP\"; label = \"Add LISP\"; width = 5; alignment = left;}"
"             }"
"             :column { width = 26;"
"               : popup_list { key = \"BatchAllLisps\"; height = 6; fixed_height = true; width = 24; fixed_width = true;}"
"             }"
"             :column { width = 16;"
"               : row {"
"                 :column { width = 8;"
"                 }"
"                 :column { width = 8;"
"                 }"
"               }"
"             }"
"           }"


"           :row {alignment = top; width = 50;"
"             :column { width = 5;"
"               : text { key = \"lisplibrary\"; label = \"Lisp Library\";}"
"             }"
"             :column { width = 37;"
"               : text { key = \"foldertext\"; label = \"Lisp Library\";}"
"             }"
"             :column { width = 8;"
"             }"
"           }"
"         }"

"        :boxed_column { label = \"\"; width = 50;"
"          :row {alignment = top;"
"            : button { key = \"EditOK\"; label = \"Change Line\"; is_cancel = true; width = 15;}"
"            : button { key = \"EditCancel\"; label = \"Cancel\"; is_cancel = true; width = 15;}"
"          }"
"        }"
"      }"

        )
        (write-line y editdes)
      )
      (not (setq editdes (close editdes)))
      (< 0 (setq editdch (load_dialog editdcl)))
      (new_dialog "editpass" editdch)
    ) ;;end of editdcl 'and' above

    (progn
      (set_tile "EditCommand" (nth (atoi LisptoEdit) (LM:str->lst lsp-command "\n")))
      (start_list "BatchAllLisps" 3)(mapcar 'add_list allthelisps)(end_list);;create Lisp files list
      (set_tile "foldertext" mylispfolder)

      (mode_tile "EditCommand" 2)
      (mode_tile "EditCommand" 3)

      (action_tile "BatchAllLisps" "(set_tile \"EditCommand\" (nth (atoi (get_tile \"BatchAllLisps\")) allthelisps))")
      (action_tile "EditOK" "(setq edittile (get_tile \"EditCommand\"))(done_dialog 1)")
      (action_tile "EditCancel" ")(done_dialog 1)")

      (start_dialog)
    ) ;;end of editdcl 'progn' above
    (princ "\nError. Unable to load dialogue box.")
  ) ;;end of editdcl 'if' above
  (vl-file-delete editdcl) ;;delete the temp editdcl file

  (if (/= edittile "")
    (progn
      (SP:commandcheck edittile allthelisps)
      (if (/= "lisp" commandOK)
        (progn
          (setq lsp-commandlist (LM:str->lst lsp-command "\n"))
          (setq lsp-commandList (replace-n edittile (atoi LisptoEdit) lsp-commandlist))
          (setq lsp-command (LM:lst->str lsp-commandList "\n"))
        );;end progn
      )

      (if (= "lisp" commandOK)
        (progn
          (AddLisps (itoa myposition) (atoi LisptoEdit))
        );;end progn
      )

      (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (LM:str->lst lsp-command "\n"))(end_list) ;;display commands list
    )
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun savescript(lsp-command / )
;;Create and open script file ;; to select a file name
  (setq fname (getfiled "Save script as:" (GetDesktop) "scr" 1)) ;;create script file
  (if (/= fname nil)(savescripta fname lsp-command))
)

(defun savescripta(fname lsp-command / )
  (setq f (open fname "w")) ;;open file
  (if (<= 1 (strlen lsp-command)) ;;if there are any commands write script
    (progn
      (write-line lsp-command f) ;;do commands
    )
  )
  (close f)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;Adding Scripts processing
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:FindScript ( / Chosenscript) ;;to select script to add
  (setq Chosenscriptpath (getfiled "Select Script" (GetDesktop) "scr" 16))
  (if (/= Chosenscriptpath nil)
    (progn
      (set_tile "scriptname" (strcat "Script::" (VL-FILENAME-BASE Chosenscriptpath)))
    )
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun loadlastscr()
  (loadscripta (strcat (getvar "TEMPPREFIX") "tempbatchscrpt.scr") "New")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun loadscript ( / Scriptfile) ;;to select script to load
  (setq Scriptfile (getfiled "Select Script" (GetDesktop) "scr" 16))
  (if (/= Scriptfile nil)(loadscripta Scriptfile "New"))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun loadscripta ( file AppendScr / fil scriptline)
  (if (findfile file)
    (progn
      (setq file (open file "r"))
      (while (setq fil (read-line file))
        (if (not (null fil))
          (setq scriptline (append scriptline (list fil)))
        ) ;end if
      ) ;end while
      (close file)

      (if (= (vl-list-length scriptline) 0)
        (progn
          (alert "Script file contains no data. Unable to load anything!") ;;alert if empty script file
        )
      )

      (if (= lsp-command "")
        (progn
          (setq AppendScr "New")
        )
      )

      (if (= AppendScr "New")
        (progn
          (setq lst scriptline)
        )
      )
      (if (= AppendScr "Append")
        (progn
          (setq lst (append (lm:str->lst lsp-command "\n") scriptline))
        )
      )
      (setq lsp-command (lm:lst->str lst "\n"))
      (if (/= (vl-list-length lst) 0)
        (progn
          (start_list "SCRIPTTEXT" 3)(mapcar 'add_list (lm:str->lst lsp-command "\n"))(end_list) ;;display commands list
        )
      )
    )
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:ChangeFolder( / selbatchdirectory) ;;select batch file folder
  (set_tile "FolderLocation2" "")
  (setq selbatchdirectory (LM:browseforfolder "Select a folder" "selbatchdirectory" 0)) ;;select a directory
  (if (/= selbatchdirectory nil) ;;if folder selection wasn't cancelled
    (progn
      (set_tile "FolderLocation1" (strcat (substr selbatchdirectory 1 70) "..."))
      (if (<= 71 (strlen selbatchdirectory)) (set_tile "FolderLocation2" (strcat "..." (substr selbatchdirectory 71 200))))
      (setq batchdirectory (strcat selbatchdirectory "\\"))
    );;end progn
  );; end if
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:batchfileslist(batchsubdirectory batchfiletype)
;;get files list from single folder
  (setq batchfileslist nil)
  (setq l nil)

  (if (= batchsubdirectory 0)
    (progn

      (setq batchfileslist (vl-directory-files batchdirectory batchfiletype nil)) ;;list of files in mylispfolder location.

;      (setq batchfileslist (vl-directory-files batchdirectory "*.dwg" nil)) ;;list of files in mylispfolder location.
      (foreach x batchfileslist (setq l (cons (strcat batchdirectory x) l))) ;;add folder to file name
      (if l 
        (setq batchfileslist (reverse l)) ;;make file list 'l' to be batchfileslist
      )
    ) ;;end progn
  ) ;;end if

;;get files list from folder + sub directories
  (if (= batchsubdirectory 1)
    (progn
      (setq batchfileslist (reverse (GrabAllFiles batchdirectory batchfiletype)))


;;      (setq batchfileslist (reverse (GrabAllFiles batchdirectory ".dwg")))
    ) ;;end progn
  )  ;;end if
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:Editfileslist()

;;Needs working out better
;;use (vl-file-systime "c:/program files/<AutoCAD installation directory>/sample/visuallisp/yinyang.lsp")
;;to display file last saved info. So can check modified in last hour, day, week, month, year


;;create DCL pop up box
  (if
    (and
      (setq dcl (strcat (getvar "TEMPPREFIX") "EditFileList.dcl"))
      (setq des (open dcl "w"))
      (foreach x
        '(
"       pass : dialog"
"       {"
"         key = \"Filesdialoguebox\";"
"         label = \"Edit Files List\";"

"         :boxed_column { label = \"Files List\"; width = 50;"
"           :row {width = 60;"
"             :row {alignment = top;"
"               :column { label = \"Batch Process these:\"; width = 50;"
"                 :row {alignment = top;"
"                   : list_box {key = \"KeepFileList\"; height = 12; fixed_height = true; width = 50; multiple_select = false;}"
"                 }"
"               }"
"               :column { label = \"Removed from batch:\"; width = 60;"
"                 :row {alignment = top;"
"                   : list_box {key = \"RemoveFileList\"; height = 12; fixed_height = true; width = 50;}"
"                 }"
"               }"
"             }"
"           }"
"         }"

;;add remove / add all buttons

"        :boxed_column { label = \"\"; width = 50;"
"          :row {alignment = top;"
"            : button { key = \"Done\"; label = \"Finished\"; is_default = false; is_cancel = true; fixed_width = true; width = 15; }"
;;"            : button { key = \"cancel\"; label = \"Cancel\"; is_default = false; is_cancel = true; fixed_width = true; width = 15; }"
"          }"
"        }"
"      }"

      )
      (write-line x des)
      )
      (not (setq des (close des)))
      (< 0 (setq dch (load_dialog dcl)))
      (new_dialog "pass" dch)
    )  ;;end of DCL 'and' above
;;End of DCL pop up box description

    (progn
      (setq TempList nil)
      (setq Tempfilename nil)
      (setq acount 0)
      (while (< acount (vl-list-length batchfileslist) )
        (setq afilename (LM:str->lst (vl-filename-base (nth acount batchfileslist)) "\n" ) )
        (setq Tempfilename (append Tempfilename afilename))
        (setq acount (+ 1 acount))
      )


      (mode_tile "KeepFileList" 2) ;;set focus to KeepfilesList

      (start_list "KeepFileList" 3)(mapcar 'add_list Tempfilename)(end_list) ;;display filename list
      (start_list "RemoveFileList" 3)(mapcar 'add_list removedfilelist)(end_list) ;;display filename list

      (setq StartKeepFileList afilename)
      (setq StartRemoveFileList RemoveFileList)

      (action_tile "KeepFileList" "(SP:Removefile (get_tile \"KeepFileList\"))")
      (action_tile "RemoveFileList" "(SP:Keepfile (get_tile \"RemoveFileList\"))")

      (action_tile "Done" "(setq ifcancel \"No\") (done_dialog)")
      (action_tile "cancel" "(setq ifcancel \"Yes\") (done_dialog)")

      (start_dialog)
    ) ;;end ofprogn above
    (princ "\nError. Unable to load dialogue box.")
  ) ;;end of DCL 'if' above
  (vl-file-delete dcl) ;;delete the temp DCL file


;;
;;add here reorder the files list
;;
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:RemoveFile(FileNumber)
  (setq TempFile (nth (atoi FileNumber) batchfileslist))
  (setq batchfileslist (LM:RemoveNth (atoi FileNumber) batchfileslist)) ;;remove file from list

  (setq Tempfilename nil)
  (Setq TempList removedfilelist)

  (setq acount 0)
  (while (< acount (vl-list-length batchfileslist) )
    (setq afilename (LM:str->lst (vl-filename-base (nth acount batchfileslist)) "\n" ) )
    (setq Tempfilename (append Tempfilename afilename))
    (setq acount (+ 1 acount))
  )
  (start_list "KeepFileList" 3)(mapcar 'add_list Tempfilename)(end_list) ;;display filename list

  (setq TempList (acad_strlsort (append TempList (LM:str->lst TempFile "\n")))) ;;sorted list

;;removed file list looses files when button is pressed again. How to fix it. Add another list updated each time.


  (setq Tempfilename nil)

  (setq acount 0)
  (while (< acount (vl-list-length TempList) )
    (setq afilename (LM:str->lst (vl-filename-base (nth acount Templist)) "\n" ) )
    (setq Tempfilename (append Tempfilename afilename))
    (setq acount (+ 1 acount))
  )
  (start_list "RemoveFileList" 3)(mapcar 'add_list Tempfilename)(end_list) ;;display filename list
  (Setq removedfilelist Tempfilename)


)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SP:KeepFile(FileNumber)

  (Setq TempList removedfilelist)

  (setq TempFile (nth (atoi FileNumber) TempList))
  (setq TempList (LM:RemoveNth (atoi FileNumber) TempList)) ;;remove file from list

  (setq Tempfilename nil)

  (setq acount 0)
  (while (< acount (vl-list-length TempList) )
    (setq afilename (LM:str->lst (vl-filename-base (nth acount TempList)) "\n" ) )
    (setq Tempfilename (append Tempfilename afilename))
    (setq acount (+ 1 acount))
  )
  (start_list "RemoveFileList" 3)(mapcar 'add_list Tempfilename)(end_list) ;;display filename list

  (Setq removedfilelist Tempfilename)
  (setq batchfileslist (acad_strlsort (append batchfileslist (LM:str->lst TempFile "\n")))) ;;sorted list
  (setq Tempfilename nil)

  (setq acount 0)
  (while (< acount (vl-list-length batchfileslist) )
    (setq afilename (LM:str->lst (vl-filename-base (nth acount batchfileslist)) "\n" ) )
    (setq Tempfilename (append Tempfilename afilename))
    (setq acount (+ 1 acount))
  )
  (start_list "KeepFileList" 3)(mapcar 'add_list Tempfilename)(end_list) ;;display filename list
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;BATCHLISPSHelp:
;;BATCHLISPSHelp:Keyboard Commands: 'BatchLisps', 'ResetBAtchLisp'
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:THERE IS NO UNDO OPTION FOR THIS COMMAND
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:Allows the user to run commands on a batch of drawings.
;;BATCHLISPSHelp:The drawings can be all the drawings in a single directory,
;;BATCHLISPSHelp:all the drawings in that directory and all its sub-directories
;;BATCHLISPSHelp:or a selection of these drawings.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:Basically if you can enter the command in text in the AutoCAD
;;BATCHLISPSHelp:command line then you can enter the command in this script writer.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:There are 2 methods to create the script:
;;BATCHLISPSHelp:Standard AutoCAD Command
;;BATCHLISPSHelp:Type the AutoCAD command in the Command edit box. Include
;;BATCHLISPSHelp:here any options that need to be used. Press the '>>Add' button.
;;BATCHLISPSHelp:Command options can be entered in the same line as the command
;;BATCHLISPSHelp:('Command' -space- 'option') or as the next command.
;;BATCHLISPSHelp:For example enter "ZOOM ALL" '>>ADD' or 
;;BATCHLISPSHelp:"ZOOM" '>>ADD' "ALL" '>>ADD'
;;BATCHLISPSHelp:There is a simple check on the entries and warning if the entry
;;BATCHLISPSHelp:is not a valid command (for example "ZOOM ALL" will be OK,
;;BATCHLISPSHelp:but "ZOOM" '>>ADD' "ALL" the command check sees "ALL" as a
;;BATCHLISPSHelp:new command and will return a warning. but since "ALL" is an
;;BATCHLISPSHelp:expected option for "ZOOM" the script will still work in this
;;BATCHLISPSHelp:case.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:Lisp and Script Commands
;;BATCHLISPSHelp:You can type the LISP command directly into the command edt box
;;BATCHLISPSHelp:or you can use the drop down list to select the list, which will
;;BATCHLISPSHelp:add its name to the Command edit box. Then press '>>Add' to add
;;BATCHLISPSHelp:it to the script list.
;;BATCHLISPSHelp:If the LISP is not saved in the Lisp Library folder (you can change
;;BATCHLISPSHelp:this) then a waring will be displayed. Note that the Script will
;;BATCHLISPSHelp:include a line to also load the LISP file (if it is in the library).
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:Script, use the 'find Script' button and then
;;BATCHLISPSHelp:the '>>ADD' button to add that sctipt to the list.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:You can edit your script list.
;;BATCHLISPSHelp:Click on the script command to display a dialogue box.
;;BATCHLISPSHelp:If you want to change a LISP command for another then make sure
;;BATCHLISPSHelp:before you edit the line that it is a LISP in thr Lisp Library.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:Select the folder on which to perform the batch process and 'sub
;;BATCHLISPSHelp:directiries' check box as required.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:Use the Edit File List button to delete files from the batch process
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:'Run batch' button will run the batch process
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:AutoCAD will open each drawing in turn and perform the commands
;;BATCHLISPSHelp:in order.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:NOTES:
;;BATCHLISPSHelp:Like most Batch routines there is no undo option
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:OPEN, QSAVE and CLOSE check boxes
;;BATCHLISPSHelp:These give the user the options to opem, save and close drawings
;;BATCHLISPSHelp:in the specified directory.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:+OPEN checkbox. Uncheck this and the batch will only run on open
;;BATCHLISPSHelp:drawings from the specified directory.
;;BATCHLISPSHelp:TIP: Clear the open check box and the script will run on the
;;BATCHLISPSHelp:current drawing only.
;;BATCHLISPSHelp:+SAVE checkbox. Checked and at the end of the script a 'QSAVE'
;;BATCHLISPSHelp:command will run on any drawings opened by the script.
;;BATCHLISPSHelp:Save Options Dialogue: This allows you to add for example, a
;;BATCHLISPSHelp:prefix of suffix to the drawing as you save it (creates a new
;;BATCHLISPSHelp:drawing) and to change the version it is saved as.
;;BATCHLISPSHelp:+CLOSE checkbox. Checked and any drawings that were opened as
;;BATCHLISPSHelp:a part of the script will be closed. Changes will not be saved
;;BATCHLISPSHelp:unless a save is specified in the script or +SAVE checkbox
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:UNDO: For any drawing that was opened, saved and closed it is
;;BATCHLISPSHelp:not possible to undo these script commands. It might be possible to
;;BATCHLISPSHelp:restore to a previous state from the back-up (.BAK) file within that
;;BATCHLISPSHelp:drawing folder.
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:
;;BATCHLISPSHelp:Occasinally BatchLisp or LispHelp LISPs hangs up, and freezes, and
;;BATCHLISPSHelp:you need to remove the temporary files to fix this... resetbatchlisp
;;BATCHLISPSHelp:does this.
;;BATCHLISPSHelp:

;;help-BATCHLISPS ;;BATCHLISPSHelp
;;help-RESETBATCHLISP ;;BATCHLISPSHelp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

Edited by Steven P
Posted

if you get a list of dwg names you can use Word or notepad++ to edit pasting in the rest of your script to each "open dwg" line, you can look for end of character, its ^p in Word and \n in Notepad ++. It is very quick to make a script once you get the hang of using the end of line replace. One warning if using Word copy and paste to notepad and save as Word has hidden characters.

 

replace \n
 Circle 0,0 20\n
jump back to top
replace 20\n
20\n line 0,0 10,10 \n

 

Posted

You can use Excel to make a script file and even use Excel to run the script in AutoCAD or just save to Notepad as script from Excel.

 

Not sure what the latest AutoCAD LT can use though. You can also use a DOS batch file.

 

Creating AutoCAD Script Files with Excel - The CAD Geek

 

How to open Autocad from excel and run a script. - Autodesk Community - AutoCAD

 

AutoCAD Quick Scripting with Spreadsheets | Autodesk University

 

create batch file to run script ? - AutoCAD Forums (cadtutor.net)

 

 

 

Does AutoCAD LT 2024 have accoreconsole? Probably not.

 

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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