Rsteel13 Posted April 16, 2009 Share Posted April 16, 2009 I need to run a LISP routine on several files contained in a user defined folder. Right now, I run the LISP after opening a DXF, which then preforms a few basic functions, then saves the file as a DWG, anc finaly closes the file. Here is the program: (defun C:3dtrs (/ tfl tpth tfilnam tfilinfo) ; Get File Path (Default Path to be C:Aegis80\Jobs\) ; Get DXF Files ; Preform Tasks below for Each file (command "erase" (ssget "X" (list (cons 8 "ELEMENTS"))) "") (command "_pedit" "M" (ssget "X") "" "y" "J" "" "") (command "-purge" "La" "ELEMENTS" "N") (command "_extrude" (ssget "X") "" "1.75" "") (command "-view" "_left") (command "rotate" (ssget "X") "" "0,0,0" "270") (setq tfl (getvar "dwgname")) (setq tpth (getvar "dwgprefix")) (setq tfilnam (substr tfl 1 (- (strlen tfl) 4))) (setq tfilinfo (strcat tpth tfilnam ".dwg")) (command "saveas" "" tfilinfo) (command "close") (princ) ) Any thoughts? I would prefere not to use a script if possible. Thanks, Bob Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 16, 2009 Share Posted April 16, 2009 I need to run a LISP routine on several files contained in a user defined folder. Right now, I run the LISP after opening a DXF, which then preforms a few basic functions, then saves the file as a DWG, anc finaly closes the file. Here is the program: Any thoughts? I would prefere not to use a script if possible. Thanks, Bob Unless VBA can bail you out, my thoughts are that a script may be your only option. I would think one could create a LISP routine to write the script for you though, if that is how you would like to proceed. Lee Quote Link to comment Share on other sites More sharing options...
Commandobill Posted April 16, 2009 Share Posted April 16, 2009 So is it that you dont want to use a script at all or you dont want to use a script personally? Either way, why dont you want to use one? Quote Link to comment Share on other sites More sharing options...
Rsteel13 Posted April 17, 2009 Author Share Posted April 17, 2009 Let me back up. I didn't think a script would work with multiple files. I tried rscript but could not get it to work. After working with scripts, I started to get frustrated, and wanted to get back to lisping (dispite the fact that I am not very good at that either). I was trying to put together a program that would run the same routine on several files that had been selected from a directory. If a script is the way to go, then I guess I have totaly missed the bus when it comes to scripting. Does the script need to run outside of AutoCad? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 17, 2009 Share Posted April 17, 2009 As far as LISPing goes - it can't run outside of the drawing very easily, unless you open all the documents that you want to alter and use Visual LISP to cycle through the Documents, and perform operations on each. But this disallows any "Command calls". Whereas with a script, you can open and close drawings, and run the commands on each one in turn. Scripts can be run within AutoCAD - under the run script in Tools I believe. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 17, 2009 Share Posted April 17, 2009 See here for more info http://www.cadtutor.net/forum/showthread.php?t=34969 Quote Link to comment Share on other sites More sharing options...
Commandobill Posted April 18, 2009 Share Posted April 18, 2009 I'm sorry to the admin's for posting another website but here's your answer http://forums.augi.com/showthread.php?t=77021 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 20, 2009 Share Posted April 20, 2009 Writing scripts is not hard particuarly for what you want. Just start autocad then "script" and run your saved script The script would be something like open c:\mydwgs\dwg1 (load "mylisp") close "Y" open c:\mydwgs\dwg2 (load "mylisp") close "Y" open c:\mydwgs\dwg3 (load "mylisp") close "Y" etc note the lisp does not need to close the file done by script nor make the lisp a defun. Remember file saved as a .SCR Once you have the script done its pretty easy to use edit and replace to create a new one. A couple of hints if you need to lots of dwg's (I have done 100 plus) you can manually create the dwg list very easy go to start Run Command change to the directory you need ie CD \mydwgs then dir *.DWG > mydwgs.txt this creates a dump of all your drawings in that directory into mydwgs.txt, Use Word and you can cut the drawing names out (hold Alt key while windowing) then use replace to create script you can replace ^p end of line with new stuff, close "Y"^p or trick it to put at start replace ^p with ^popenC:\mydwgs\ its very fast once you know how. note ^p is the carriage return as I have typed carat lower case p Quote Link to comment Share on other sites More sharing options...
Commandobill Posted April 20, 2009 Share Posted April 20, 2009 filedia 0 open "c:\mydwgs\dwg1.dwg" (load "c:/mylisp") (c:mylisp) close "Y" open "c:\mydwgs\dwg2.dwg" (load "c:/mylisp") (c:mylisp) close "Y" open "c:\mydwgs\dwg3.dwg" (load "c:/mylisp") (c:mylisp) close "Y" etc filedia 1 I had to edit your script a little... cheers Also i would suggest a lisp to get a list of drawings in that directory. Then you could use the lisp to write and run the script... Quote Link to comment Share on other sites More sharing options...
Patrick_35 Posted April 20, 2009 Share Posted April 20, 2009 Hi i would suggest a lisp to get a list of drawings in that directory (defun test(/ dirbox rep) (defun dirbox(title flag / cdl rep) (if (setq cdl (vlax-create-object "Shell.Application")) (progn (and (setq rep (vlax-invoke cdl 'browseforfolder 0 title flag "")) (setq rep (vlax-get-property (vlax-get-property rep 'self) 'path)) ) (vlax-release-object cdl) ) ) rep ) (if (setq rep (dirbox "Title" 512)) (vl-directory-files rep "*.*" 1) ) ) @+ Quote Link to comment Share on other sites More sharing options...
MiGo Posted April 20, 2009 Share Posted April 20, 2009 I'm sorry to the admin's for posting another website but here's your answer http://forums.augi.com/showthread.php?t=77021 I love script pro. We use it all the time, the only quark with it is it opens autocad for each drawing and closes it. When closing cad it seems to force an error, so for each dwg you get the AutoCAD error msg that you would typically send to them. Quote Link to comment Share on other sites More sharing options...
Commandobill Posted April 20, 2009 Share Posted April 20, 2009 I dont think you need script pro... I think if you took your lisp and had it write a script that told autocad to run a lisp for each one of the .dwg's it found then the puzzle would be complete... just nobody has simplified it to that level yet... Everyone seems to think you need to write a script and write a lisp. But you can have lisp write the script for you and have it re-write it for any situation... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2009 Share Posted April 20, 2009 Something as simple as this should do: (defun c:rscr (/ wfile rfile ofile) (if (and (setq wfile (getfiled "\nSelect File to Write to: " "" "scr" 1)) (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" )) (progn (setq ofile (open wfile "w")) (foreach x (vl-directory-files (vl-filename-directory rfile) "*.dwg" 1) (write-line (strcat "open " x " (load \"mylisp\") close \"Y\"") ofile)) (close ofile)) (princ "\n<!> File Selection Error <!>")) (princ)) Which could be very easily modified. Quote Link to comment Share on other sites More sharing options...
Shawndoe Posted April 21, 2009 Share Posted April 21, 2009 Hi, Personally I dislike mixing scripts and LISP routines. It just feels... wrong. So I came up with a way around it. My code is covered by an NDA so I can't post it for you, but I'll give you the steps you need to excute without scripts. I. Create a routine to run from drawing1. a. Create a list of routines to run. b. Create a list of work drawings for processing. c. Place the routines list in the vlisp blackboard. d. Open the first work drawing in list. 1. Drawing1 lisp processing is suspended. 2. Startup routine in acad20xxdoc.lsp begins. 3. See Section II e. Save and Close current work drawing. f. Back to step d and open next work drawing in list.II. Create startup routine for acad20xxdoc.lsp a. Check vlisp blackboard for routines list. 1. If there load the first routine. 2. Otherwise normal startup b. Execute the routine. 1. This is the actual work you want done to the drawings. 2. See section III c. Repeat from step a for all routines in list. d. Do not set the work drawing as active. 1. Opening a drawing is different from making it active. 2. When made active, control will not return to drawing1. 3. Inactive drawings will execute all startup routines then hand control back to the last active drawing.III. Create the routines to make your drawing changes. a. Can be any routine that does not require user input.[/Code] This will run any routine that doesn't need command line input. The command line is unavailable until after all startup routines have finished. This means no getstrings or other command line user inputs. If you end up needing user input you'll have to make a DCL to get it. Let me know if you have any questions and I'll try to help. Have a good one.Shawndoe Quote Link to comment Share on other sites More sharing options...
Commandobill Posted April 21, 2009 Share Posted April 21, 2009 Something as simple as this should do: (defun c:rscr (/ wfile rfile ofile) (if (and (setq wfile (getfiled "\nSelect File to Write to: " "" "scr" 1)) (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" )) (progn (setq ofile (open wfile "w")) (foreach x (vl-directory-files (vl-filename-directory rfile) "*.dwg" 1) (write-line (strcat "open " x " (load \"mylisp\") close \"Y\"") ofile)) (close ofile)) (princ "\n<!> File Selection Error <!>")) (princ)) Which could be very easily modified. It works but only allows for single selection... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 21, 2009 Share Posted April 21, 2009 It works but only allows for single selection... Single Selection???? You select one file from the directory containing all the files you want and it gets them all... Quote Link to comment Share on other sites More sharing options...
Commandobill Posted April 21, 2009 Share Posted April 21, 2009 My apologies. I was multitasking and didn't realize. It works brilliantly. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 21, 2009 Share Posted April 21, 2009 My apologies. I was multitasking and didn't realize. It works brilliantly. You had me worried for a minute there.. No worries dude, Cheers Lee Quote Link to comment Share on other sites More sharing options...
Rsteel13 Posted April 22, 2009 Author Share Posted April 22, 2009 Lee Mac, I adapted your code with the following changes: (defun c:rscr (/ wfile rfile ofile) (if (and (setq wfile (getfiled "\nSelect File to Write to: " "" "scr" 1)) (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dxf" )) (progn (setq ofile (open wfile "w")) (foreach x (vl-directory-files (vl-filename-directory rfile) "*.dxf") (write-line (strcat "open " x " (load \"3dtrs.lsp\") close \"Y\"") ofile)) (close ofile)) (princ "\n<!> File Selection Error <!>")) (princ)) And Get the following results in my newly created .scr file: open G01.dxf (load "3dtrs.lsp") close "Y" open H01.dxf (load "3dtrs.lsp") close "Y" open J02.dxf (load "3dtrs.lsp") close "Y" open J03.dxf (load "3dtrs.lsp") close "Y" open J04.dxf (load "3dtrs.lsp") close "Y" open T02.dxf (load "3dtrs.lsp") close "Y" When I run the script, Autocad cannot find the files, since no path is shown. I have tried changing the FLAGS for the directory settings but cannot produce anything of value. Any thoughts? Thanks, Robert Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 22, 2009 Share Posted April 22, 2009 I also tried to modify the flags, but with no luck. I think the easiest (and cheating way) out of this would be to either change the ACAD search path to search in your folder also, or to make a folder in the ACAD search path and put the files there. But I am stuck otherwise Quote Link to comment Share on other sites More sharing options...
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.