PipelinerUSA Posted November 22, 2021 Posted November 22, 2021 I have a directory populated with several hundreds of drawings and scripts. For every drawing "A.dwg" there is a script "A.scr": A.dwg A.scr B.dwg B.scr C.dwg C.scr D.dwg D.scr ... Every script is unique. What I am looking to do is figure out a way to run every script on its associated drawing. Tools like ScriptPro.exe and the Civil 3D out-of-the-box Batch Save Utility work by running 1 script on many drawings in a folder, but in my case there is one unique script to be ran on one unique drawing. Any ideas would be appreciated. Quote
dan20047 Posted November 22, 2021 Posted November 22, 2021 have a single script with this content? then each drawing will run a script with same file name (command "script" (strcat (vl-filename-base (getvar "dwgname")) ".scr")) 1 Quote
rlx Posted November 22, 2021 Posted November 22, 2021 written between diner & tea-time (and totally untested) t1 uses multi thread (set time in wait to match time it takes for script to process one drawing) t2 uses single thread and creates a bat file in c:\temp\tmp.bat but I like dan20047's approach in case you already have a mother script ok , tea time now ;;; rlx 22-nov-2021 (defun c:t1 ( / f l s) (if (and (setq f (Select-a-Folder "Select Folder with drawings & scripts"))(setq l (alf f "*.dwg" t))) (foreach d l (setq s (strcat (car (fnsplitl d)) (cadr (fnsplitl d)) ".scr")) (command "start" (strcat "accoreconsole.exe /i " "\"" d "\"" " /s " "\"" s "\"" " /l en-us"))(wait 3)))) (defun c:t2 ( / f l s n p) (if (and (setq f (Select-a-Folder "Select Folder with drawings & scripts")) (setq l (alf f "*.dwg" t))(setq p (open (setq n "c:\\temp\\tmp.bat") "w"))) (foreach d l (setq s (strcat (car (fnsplitl d)) (cadr (fnsplitl d)) ".scr")) (write-line (strcat "accoreconsole.exe /i " "\"" d "\"" " /s " "\"" s "\"" " /l en-us") p) (write-line "timeout /t 1 /nobreak" p)))(if p (progn (write-line "exit" p)(close p)(gc)(command "start" n)))) (defun wait (sec / stop) (setq stop (+ (getvar "DATE") (/ sec 86400.0))) (while (> stop (getvar "DATE")))) ;;; generic getfolder routine with possibility to create a new subfolder (Select-a-Folder "select path") (defun Select-a-Folder ( m / f s) (if (and (setq s (vlax-create-object "Shell.Application")) (setq f (vlax-invoke s 'browseforfolder 0 m 0 "")))(setq f (vlax-get-property (vlax-get-property f 'self) 'path)) (setq f nil))(vl-catch-all-apply 'vlax-release-object (list s)) (if f (vl-string-translate "/" "\\" f))) ;;; d = directory , e = extension like "*.dwg" , f = flag include subfolders (any value or nil) ;;; test : (alf "d:/temp/lisp" "*.*" t) (alf "d:/temp/lisp" "*.dwg" nil) (defun alf (d e f) (setq d (vl-string-right-trim "\\" (vl-string-translate "/" "\\" d))) (if f (apply 'append (cons (if (vl-directory-files d e)(mapcar '(lambda (x)(strcase (strcat d "\\" x)))(vl-directory-files d e))) (mapcar '(lambda (x) (alf (strcase (strcat d "\\" x)) e f))(vl-remove ".." (vl-remove "." (vl-directory-files d nil -1)))))) (mapcar '(lambda (x)(strcase (strcat d "\\" x))) (vl-directory-files d e 1)))) Quote
BIGAL Posted November 23, 2021 Posted November 23, 2021 There has been a lot of process multiple dwgs this may be useful to create a bat file using RLX code as a start but processing a file of dwg names, you would replace the hard code path with the path from select a folder. Adding /S will give subfolders as well. (command "shell" "dir D:\\acadtemp\\*.dwg /b >d:\\acadtemp\\dirdwg.txt" ) Also Pairing scripts to be run on associated drawings and batch processing (theswamp.org) 1 Quote
PipelinerUSA Posted November 23, 2021 Author Posted November 23, 2021 21 hours ago, dan20047 said: have a single script with this content? then each drawing will run a script with same file name (command "script" (strcat (vl-filename-base (getvar "dwgname")) ".scr")) My project is for a bunch of comm. towers that all have different assets attached to them. Those assets exist in a block catalog. I have a script for each tower that inserts those blocks at the appropriate location. Each tower is 1 drawing, and they are all unique. Also included in the script is the creation of property filters and their definitions (wildcard criteria), layer color assignments, etc. Would this work for what I need to do? Thanks Quote
dan20047 Posted November 23, 2021 Posted November 23, 2021 You mentioned ScriptPro, while I haven't used it, I assumed you had tested it. I also assume ScriptPro works by opening each drawing and then running the selected script. My thought is that you could run a single script with the line above, and that script would use the active drawing name to call another script you already have in the same folder as the drawing being opened. If you don't have ScriptPro, there are other solutions, such as RLX posted. Are you familiar with the basics of lisp coding? Quote
PipelinerUSA Posted November 23, 2021 Author Posted November 23, 2021 2 hours ago, dan20047 said: You mentioned ScriptPro, while I haven't used it, I assumed you had tested it. I also assume ScriptPro works by opening each drawing and then running the selected script. My thought is that you could run a single script with the line above, and that script would use the active drawing name to call another script you already have in the same folder as the drawing being opened. If you don't have ScriptPro, there are other solutions, such as RLX posted. Are you familiar with the basics of lisp coding? I have used ScriptPro. It executes one script across a number of drawings. I seek out LISP routines and use them regularly, but I have not written my own. I am familiar with the syntax though. But I am not experienced in making my own. Quote
dan20047 Posted November 23, 2021 Posted November 23, 2021 The code I gave you is lisp, but you can put it into a script file, and it should work, say call it PS.scr. The concept is scriptPro runs PS.scr on each drawing: Open A.dwg Run PS.scr (scriptPro does this) PS.scr > runs A.scr Close A.dwg (scriptPro does this) Open B.dwg Run PS.scr PS.scr > runs B.scr etc.. I added a check to be sure the script can be found. You can test this script by opening drawing A, type script, then select the file. It should then also run script A.scr for you. If you have problems, post the command history to show the error message. ;;; create variable for script based on drawing filename, example "A.scr" (setq scrFileName (strcat (vl-filename-base (getvar "dwgname")) ".scr")) ;;; run script if it can be found (if (findfile scrFileName) (command ".script" scrFileName)) Quote
dan20047 Posted November 23, 2021 Posted November 23, 2021 See also http://www.lee-mac.com/scriptwriter.html, which may work instead of ScriptPro. Quote
BIGAL Posted November 24, 2021 Posted November 24, 2021 What is in script "a.scr" can it be re-made as a lisp then script will work for one after another dwg. Open A.dwg (load "a.lsp) Close Y Open b.dwg (load "b.lsp) Close Y Quote
PipelinerUSA Posted December 6, 2021 Author Posted December 6, 2021 On 11/23/2021 at 9:08 PM, BIGAL said: What is in script "a.scr" can it be re-made as a lisp then script will work for one after another dwg. Open A.dwg (load "a.lsp) Close Y Open b.dwg (load "b.lsp) Close Y An example of "a.scr" is the following: -layer filter new property .... (sets up layer filter rules so layers are automatically filtered correctly in layer manager panel) -layer new layername ... (creates new layers and sets current for subsequent block insertion) -insert filepath coordinates scale ... (places already created blocks from a catalog/directory into the model at defined coords) -layer color colornumber layernamewildcard ... (changes color of layers based on naming wildcards) -qsave -quit The reason I have struggled to find a way to scale the execution of all these scripts is the fact that "a.scr" and "b.scr", while containing the same commands, are completely different. The contents of the scripts are generated from a master Excel workbook that I export groups of rows to text files and save with unique names. I appreciate all the suggestions from everyone, but still struggling with getting anything to work Quote
BIGAL Posted December 6, 2021 Posted December 6, 2021 Ok so excel has VBA so you can write scripts as you mention but why not also write a master batch file and use accorreconsole. it can be just a column with the correct columns of text added together that you copy to a notepad file. Use Excel Concatenate function. Only difference is that its ran from the windows CMD or as a shell function in lisp. cd\ cd c:\Program files\Autodesk\Autocad 2020 accoreconsole.exe /i d:\alan\test.dwg /s d:\alan\lisp\test.scr accoreconsole.exe /i d:\alan\a.dwg /s d:\alan\lisp\a.scr accoreconsole.exe /i d:\alan\b.dwg /s d:\alan\lisp\b.scr Quote
PipelinerUSA Posted December 10, 2021 Author Posted December 10, 2021 On 12/6/2021 at 5:06 PM, BIGAL said: Ok so excel has VBA so you can write scripts as you mention but why not also write a master batch file and use accorreconsole. it can be just a column with the correct columns of text added together that you copy to a notepad file. Use Excel Concatenate function. Only difference is that its ran from the windows CMD or as a shell function in lisp. cd\ cd c:\Program files\Autodesk\Autocad 2020 accoreconsole.exe /i d:\alan\test.dwg /s d:\alan\lisp\test.scr accoreconsole.exe /i d:\alan\a.dwg /s d:\alan\lisp\a.scr accoreconsole.exe /i d:\alan\b.dwg /s d:\alan\lisp\b.scr Thanks for laying out the contents of what the .bat should be. Making progress and finding success using accoreconsole.exe and the /i and /s switches. Quote
Steven P Posted December 11, 2021 Posted December 11, 2021 Does this work from dan20047? If you made it into a LISP with a '(defun c:..... ( / )' at the beginning and a ')' at the end? On 11/22/2021 at 5:55 PM, dan20047 said: (command "script" (strcat (vl-filename-base (getvar "dwgname")) ".scr")) You could try and see if this works, my batch Lisp, it is not as good as I want (it will only process closed files for example, plus the file that you run it from). It works by opening each file, processing the required commands and then saving and closing the file... but since it opens and closes files it is a lot slower than accoreconsole. Programming isn;t so neat and is a lot of things joined together as I think of new ideas... and not everything works.. but for a basic batch processing is OK. A 'Find' button links to another LISP file so doesn't work, script file Find button works. Command is batchlisps BATCHLISPS.lsp Quote
Recommended Posts
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.