au-s Posted May 11, 2009 Posted May 11, 2009 Almost, I think: [b][color=red]([/color][/b][b][color=blue]defun[/color][/b] c:rscr [b][color=red]([/color][/b][b][color=blue]/[/color][/b] wfile rfile ofile dir[b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]if[/color][/b] [b][color=red]([/color][/b][b][color=blue]and[/color][/b] [b][color=red]([/color][/b][b][color=blue]setq[/color][/b] wfile [b][color=red]([/color][/b][b][color=blue]getfiled[/color][/b] [b][color=#ff00ff]"\nSelect File to Write to: "[/color][/b] [b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"scr"[/color][/b] [b][color=#009900]1[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]setq[/color][/b] rfile [b][color=red]([/color][/b][b][color=blue]getfiled[/color][/b] [b][color=#ff00ff]"\nSelect File from Directory to Read: "[/color][/b] [b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"dwg"[/color][/b] [b][color=#009900]8[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]progn[/color][/b] [b][color=red]([/color][/b][b][color=blue]setq[/color][/b] ofile [b][color=red]([/color][/b][b][color=blue]open[/color][/b] wfile [b][color=#ff00ff]"w"[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]foreach[/color][/b] x [b][color=red]([/color][/b][b][color=blue]vl-directory-files[/color][/b] [b][color=red]([/color][/b][b][color=blue]setq[/color][/b] dir [b][color=red]([/color][/b][b][color=blue]vl-filename-directory[/color][/b] rfile[b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=#ff00ff]"*.dwg"[/color][/b] [b][color=#009900]1[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]write-line[/color][/b] [b][color=red]([/color][/b][b][color=blue]strcat[/color][/b] [b][color=#ff00ff]"open "[/color][/b] [b][color=#ff00ff]"\"[/color][/b][b][color=#ff00ff]" dir "[/color][/b]\\[b][color=#ff00ff]" x "[/color][/b]\[b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"(load \"[/color][/b]mylisp\[b][color=#ff00ff]") (c:mylisp) close \"[/color][/b]Y\[b][color=#ff00ff]""[/color][/b][b][color=red])[/color][/b] ofile[b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]close[/color][/b] ofile[b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]princ[/color][/b] [b][color=#ff00ff]"\n<!> File Selection Error <!>"[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]command[/color][/b] [b][color=#ff00ff]"script"[/color][/b] wfile[b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]princ[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] Hey, This is neat ... I was trying to make lisp write the scr file directly. Couldnt do it ... why? This is how I did it: [b][color=red]([/color][/b][b][color=blue]defun[/color][/b] c:rscr [b][color=red]([/color][/b][b][color=blue]/[/color][/b] wfile rfile ofile dir[b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]if[/color][/b] [b][color=red]([/color][/b][b][color=blue]and[/color][/b] [color=red][i][b]([/b][b]setq[/b] wfile [b]([/b][b]strcat[/b] [b]"C:\\temp.scr[/b][b])[/b][/i][/color][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]setq[/color][/b] rfile [b][color=red]([/color][/b][b][color=blue]getfiled[/color][/b] [b][color=#ff00ff]"\nSelect File from Directory to Read: "[/color][/b] [b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"dwg"[/color][/b] [b][color=#009900]8[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]progn[/color][/b] [b][color=red]([/color][/b][b][color=blue]setq[/color][/b] ofile [b][color=red]([/color][/b][b][color=blue]open[/color][/b] wfile [b][color=#ff00ff]"w"[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]foreach[/color][/b] x [b][color=red]([/color][/b][b][color=blue]vl-directory-files[/color][/b] [b][color=red]([/color][/b][b][color=blue]setq[/color][/b] dir [b][color=red]([/color][/b][b][color=blue]vl-filename-directory[/color][/b] rfile[b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=#ff00ff]"*.dwg"[/color][/b] [b][color=#009900]1[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]write-line[/color][/b] [b][color=red]([/color][/b][b][color=blue]strcat[/color][/b] [b][color=#ff00ff]"open "[/color][/b] [b][color=#ff00ff]"\"[/color][/b][b][color=#ff00ff]" dir "[/color][/b]\\[b][color=#ff00ff]" x "[/color][/b]\[b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"(load \"[/color][/b]mylisp\[b][color=#ff00ff]") (c:mylisp) close \"[/color][/b]Y\[b][color=#ff00ff]""[/color][/b][b][color=red])[/color][/b] ofile[b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]close[/color][/b] ofile[b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]princ[/color][/b] [b][color=#ff00ff]"\n<!> File Selection Error <!>"[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]command[/color][/b] [b][color=#ff00ff]"script"[/color][/b] wfile[b][color=red])[/color][/b] [b][color=red]([/color][/b][b][color=blue]princ[/color][/b][b][color=red])[/color][/b][b][color=red])[/color][/b] That lets user open the temp.scr and use this temp.scr to another lisp load... So the file temp.scr always over-writes itself depending on what lisp you choose to load... I red marked the line... Thanx in advance Quote
Lee Mac Posted May 11, 2009 Posted May 11, 2009 (defun c:rscr (/ wfile rfile ofile dir) (if (and (setq wfile "C:\\test.scr") (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" )) (progn (setq ofile (open wfile "w")) (foreach x (vl-directory-files (setq dir (vl-filename-directory rfile)) "*.dwg" 1) (write-line (strcat "open " "\"" dir "\\" x "\"" "(load \"mylisp\") (c:mylisp) close \"Y\"") ofile)) (close ofile)) (princ "\n<!> File Selection Error <!>")) (command "script" wfile) (princ)) Quote
au-s Posted May 11, 2009 Posted May 11, 2009 This is another attempt... ALERTS: Invalid file name Why? (defun c:testing3 (/ wfile rfile ofile dir) (if (and (setq scr "temp.scr") (setq wfile (strcat (dos_tempdir) scr)) (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" )) (progn (setq ofile (open wfile "w")) (foreach x (vl-directory-files (setq dir (vl-filename-directory rfile)) "*.dwg" 1) (write-line (strcat "open " "\"" dir "\\" x "\"" "(load \"mylisp\") (c:mylsp) close \"Y\"") ofile)) (close ofile)) (princ "\n<!> File Selection Error <!>")) (command "script" wfile) (princ)) (dos_tempdir) is DOSlib function which reads the logged in users temp folder. I am also trying hard to make the lisp choose only files I want to, not a every file under a directory... Multiple file selection... I can do it with (dos_getfilem) but then it crashes... I think it might do something with the vl-file-directory??? (dos_getfilem) (dos_getfilem "Select a file" "C:\\Program Files\\Autocad 2006\\" "Drawing files (*.dwg)|*.dwg|All files (*.*)|*.*||") Quote
Lee Mac Posted May 11, 2009 Posted May 11, 2009 yes, I tried that version ... I believe you had "Strcat" in your wfile, and hadn't finished the quotation marking, so I doubt it was this version you tried. but it alerts Invalid filename while in Autocad, then I can choose the files again... with "open" Select files... I can get this version to work: (defun c:rscr (/ wfile rfile ofile dir) (if (and (setq wfile "C:\\test.scr") (setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" )) (progn (setq ofile (open wfile "w")) (foreach x (vl-directory-files (setq dir (vl-filename-directory rfile)) "*.dwg" 1) (write-line (strcat "open \"" dir "\\" x "\" (load \"mylisp\") (c:mylisp) close \"Y\"") ofile)) (close ofile) (command "script" wfile)) (princ "\n<!> File Selection Error <!>")) (princ)) I wouldn't recommend having the script running after it is written, but rather I would run it manually. Also, as for selecting each drawing from a list - I think this may be a job for DCL, not getfiled. Quote
au-s Posted May 12, 2009 Posted May 12, 2009 Okej ... No I got this .. It creates the script file but it seems not to write any lines in it... (defun c:rscr (/ wfile rfile ofile n) (if (and (setq wfile "C:\\test.scr") (setq rfile (dos_getfilem "Select Drawings" "" "DWG Files (*.dwg)|*.dwg")) ) (progn (setq ofile (open wfile "w")) (foreach n '(write-line (strcat "open \"" rfile "\" (load \"mylisp\") (c:mylisp) close \"Y\"") ofile)) (close ofile) (command "script" wfile)) (princ "\n<!> File Selection Error <!>")) (princ)) Sorry for bothering... Anyone experiance in DOSlib? Quote
au-s Posted May 12, 2009 Posted May 12, 2009 I solved it with this lisp: (defun c:rscr (/ flag thelist thedir nfiles thefile fn ctr dname) ;set the flag (setq flag T) ;check Doslib is loaded (if (not (member "doslib17.arx" (arx))) (progn (if (findfile "doslib17.arx") (arxload "doslib17") (progn (alert "DosLib not installed") (setq flag nil) );progn );if );progn );if ;if DosLib is installed and loaded (if flag ;do the following (progn (progn (setq thelist (dos_getfilem "Select Drawings" "" "DWG Files (*.dwg)|*.dwg")) ;retrieve the directory (setq thedir (car thelist)) ;retrieve the file names (setq thelist (cdr thelist)) ;get the number of files (setq nfiles (length thelist)) (setq thefile "C:\\temp.scr") (setq fn (open thefile "w")) (setq ctr 0) (repeat nfiles (setq dname (nth ctr thelist)) (write-line (strcat "open \"" thedir dname "\" (load \"mylisp.lsp\") (c:mylisp) close \"Y\"") fn) (setq ctr (1+ ctr)) );end repeat (close fn) (command "script" thefile) (princ "\n<!> File Selection Error <!>"))) (princ))) I got a bit of errors coming up though... The lisp goes as planend but some "malformed list on input" messages coming up during execution Quote
RM223 Posted October 8, 2013 Posted October 8, 2013 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... I am having an issue attempting to process a script similar to what you were talking about in this thread. Example from thread: 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 The issue I am having is that after I run my Lisp routine it never returns control to the script. From the above example, it opens dwg1.dwg and runs C:mylisp but that's it. It doesn't even execute the "Close" command. I'm guessing it is because of my lisp file is running external lisp functions but I'm not sure. If this is correct, where can I find some documentation on the rules. If this is not correct, what am I doing wrong? Here is a shortened version of my Script (setvar "FILEDIA" 0) open "N:\PROJECTS\01_1040_AFM.dwg" (LOAD "N:\AFM20\hrmx.LSP") (C:hrm) CLOSE "Y" open "N:\PROJECTS\02_1040_AFM.dwg" (LOAD "N:\AFM20\hrmx.LSP") (C:hrm) CLOSE "Y" (setvar "FILEDIA" 1) Thanks in advance for any help Sorry if I'm not placing this post in the correct place..... I'm a Newbie Quote
Lee Mac Posted October 8, 2013 Posted October 8, 2013 The issue I am having is that after I run my Lisp routine it never returns control to the script. From the above example, it opens dwg1.dwg and runs C:mylisp but that's it. It doesn't even execute the "Close" command. Is your program cancelling a command?, e.g.: (command "_.-insert" nil) or: (command "_.-insert") (command) Since an AutoCAD Script is nothing more than a sequence of commands issued to the command-line, cancelling a command will in turn cease evaluation of the Script. Quote
RM223 Posted October 8, 2013 Posted October 8, 2013 Is your program cancelling a command?, e.g.: (command "_.-insert" nil) or: (command "_.-insert") (command) Since an AutoCAD Script is nothing more than a sequence of commands issued to the command-line, cancelling a command will in turn cease evaluation of the Script. Not that I am aware of. If I open a drawing manually and run the HRM lisp routine, it completes it successfully. Even using the script the lisp completes (last command is to publish drawings to PDF) successfully. Quote
RM223 Posted October 8, 2013 Posted October 8, 2013 I was able to resolve the issue using ScripPro. So far it is working great! 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.