<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Batch file to create a script which runs a lisp command on each drawing file in the same directory. in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12347910#M22313</link>
    <description>&lt;P&gt;you could try including at the start of the script:&lt;/P&gt;&lt;P&gt;Filedia 0&lt;/P&gt;&lt;P&gt;and then after opening the last drawing:&lt;/P&gt;&lt;P&gt;Filedia 1&lt;/P&gt;</description>
    <pubDate>Wed, 01 Nov 2023 23:52:56 GMT</pubDate>
    <dc:creator>paullimapa</dc:creator>
    <dc:date>2023-11-01T23:52:56Z</dc:date>
    <item>
      <title>Batch file to create a script which runs a lisp command on each drawing file in the same directory.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12344962#M22309</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a batch file which creates a single script file which i can drop into cad and that script file will open a drawing in a directory (same as batch file) and then load a lisp routine (also in same directory) then run that lisp command, save and close that drawing file and then cycle through each drawing in the same directory and run those same commands.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is what i have so far which does what i want it to do however it just endlessly creates the script for only the first drawing from the list instead of going to the next drawing in the list and eventually ending after the list is finished.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;@Anonymous off

REM Get the current directory
set script_dir=%~dp0

REM Create the list file
dir /b "%script_dir%*.dwg" &amp;gt; "%script_dir%drawing_list.txt"

REM Create the script file
echo (setq script (open "%script_dir%temp_script.scr" "a")) &amp;gt; "%script_dir%temp_script.scr"

REM Read the first line from the list file
set /p drawing=&amp;lt;"%script_dir%drawing_list.txt"

REM Loop through each drawing in the list file
:loop
if not defined drawing goto :eof

REM Add the commands for the current drawing to the script file
echo (command "_open" "%script_dir%%drawing%") &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
echo (command "_load" "MyProgram.lsp" nil) &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
echo (command "(c:MyCommand)") &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
echo (command "_qsave") &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
echo (command "_close") &amp;gt;&amp;gt; "%script_dir%temp_script.scr"

REM Read the next line from the list file
set /p drawing=&amp;lt;"%script_dir%drawing_list.txt"

REM Continue looping through the drawings
goto :loop&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 23:03:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12344962#M22309</guid>
      <dc:creator>Kate.RobinsonR9FXS</dc:creator>
      <dc:date>2023-10-31T23:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Batch file to create a script which runs a lisp command on each drawing file in the same directory.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12345397#M22310</link>
      <description>&lt;P&gt;Would be curious to see the resulting contents in the script. If it doesn’t show the echo command to open the next dwg in the directory list then the set /p drawing is not working&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also I’m not sure how you’re able to get the following 2 lines to execute:&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;echo (command "_load" "MyProgram.lsp" nil) &amp;gt;&amp;gt; "%script_dir%temp_script.scr"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;echo (command "(c:MyCommand)") &amp;gt;&amp;gt; "%script_dir%temp_script.scr"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;The proper syntax should look something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;echo (load"MyProgram") &amp;gt;&amp;gt; "%script_dir%temp_script.scr"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;echo (c:MyCommand) &amp;gt;&amp;gt; "%script_dir%temp_script.scr"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2023 04:36:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12345397#M22310</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2023-11-01T04:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Batch file to create a script which runs a lisp command on each drawing file in the same directory.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12345585#M22311</link>
      <description>&lt;P&gt;Give this a shot which only works if there are no spaces in the directory name. Save the file as a .bat or .cmd file and run it.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;@Anonymous off
REM Only works if there are no spaces in the current directory name
REM Get the current directory
set script_dir=%~dp0

REM Create the list file
dir /b "%script_dir%*.dwg" &amp;gt; "%script_dir%drawing_list.txt"

REM Create the script file
REM echo (setq script (open "%script_dir%temp_script.scr" "a")) &amp;gt; "%script_dir%temp_script.scr"

REM Loop through drawing list file
For /F "tokens=* delims=" %%a in (%script_dir%drawing_list.txt) do (
echo open ^"%script_dir%%%a^" &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
echo ^(load"MyProgram"^) &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
echo ^(c:MyCommand^) &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
echo qsave &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
echo close &amp;gt;&amp;gt; "%script_dir%temp_script.scr"
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2023 07:14:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12345585#M22311</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2023-11-01T07:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Batch file to create a script which runs a lisp command on each drawing file in the same directory.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12347891#M22312</link>
      <description>&lt;P&gt;Have actually managed to get this to work by pasting a couple of batch files together (even with directory spaces). Although have removed the load command and just loaded the lisps into my startup.&lt;/P&gt;&lt;P&gt;Now having trouble when running the script, it still opens the dialog box for opening a dwg despite the script having the full path of the dwg name and location? any thoughts what this issue could be? I feel like there is a system variable amiss here.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;@Anonymous off

echo Going to execute DRGList
dir /b /o:n *.dwg &amp;gt; DRGList.txt
call :append DRGList.txt
echo Returned from DRGList

echo Going to execute List
call :temp_script DRGList.txt
echo Returned from List
::echo.&amp;amp;pause

echo.&amp;amp;goto :eof

:append
REM Appends the current directory to each line in a text file
REM %1 - file name to append the string to
SETLOCAL
set "f=%~1"
(for /f "tokens=*" %%a in (%f%) do (
    echo %cd%\%%a
)) &amp;gt; "%temp%\t0815.txt"
move /y "%temp%\t0815.txt" "%f%"
EXIT /b

:temp_script
REM Creates a script to open the drawings, apply commands, save, and close
REM %1 - file name to create the script for
SETLOCAL
set "f=%~1"
(for /f "tokens=*" %%a in (%f%) do (
echo open ^"%%a^"
echo Mycommand
echo qsave 
echo close 
)) &amp;gt; "temp_script.scr"
EXIT /b&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Nov 2023 23:39:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12347891#M22312</guid>
      <dc:creator>Kate.RobinsonR9FXS</dc:creator>
      <dc:date>2023-11-01T23:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Batch file to create a script which runs a lisp command on each drawing file in the same directory.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12347910#M22313</link>
      <description>&lt;P&gt;you could try including at the start of the script:&lt;/P&gt;&lt;P&gt;Filedia 0&lt;/P&gt;&lt;P&gt;and then after opening the last drawing:&lt;/P&gt;&lt;P&gt;Filedia 1&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2023 23:52:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-file-to-create-a-script-which-runs-a-lisp-command-on-each/m-p/12347910#M22313</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2023-11-01T23:52:56Z</dc:date>
    </item>
  </channel>
</rss>

