TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: au-s on May 12, 2009, 02:57:10 AM
-
Hello
I have this lisp from LEEMAC on CADtutor which writes a script file and then executes a command in lisp:
Here is the code
(defun c:rscr (/ wfile rfile ofile dir)
(if (and (setq wfile "C:\\test.scr")
(setq rfile (getfiled "\nSelect File from Directory to Read: " "" "dwg" 8)))
(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 cant multiple select files here.
I know that I can select files "multiple selection" without DCL and with DOSLib.
I wrote a bit of code and changed that.
Now .. with dos_getfilem I can choose multiple files.
But I think that the lisp cant understand whjat files are chosen when I try to writle-line to the script file... the format of it...
Can anyone help.
Here below is the code I tried to manipulate.
(defun c:rscr (/ wfile rfile ofile dir)
(if (and (setq wfile "H:\\test.scr")
(setq rfile (dos_getfilem "Select Drawings"
"" "DWG Files (*.dwg)|*.dwg"))
)
(progn
(setq ofile (open wfile "w"))
(foreach rfile
(write-line
(strcat "open \"" rfile "\" (load \"mylisp\") (c:mylisp) close \"Y\"")
ofile))
(close ofile)
(command "script" wfile))
(princ "\n<!> File Selection Error <!>"))
(princ))
-
I modified but now it is nothing written into the file...
The file creates but it is empty and the output is cant open test.scr
(defun c:rscr (/ wfile rfile ofile n)
(if (and (setq wfile "H:\\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 \"K:/CAD/AIX-meny-2008/Lisp/attribut/AIX_ExportDörrLittera.lsp\") (c:AIX:EXPORTDORRLITT) close \"Y\"")
ofile))
(close ofile)
(command "script" wfile))
(princ "\n<!> File Selection Error <!>"))
(princ))
-
SOLVED with this one
(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 (strcat (dos_tempdir)"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)))
Allthough it pronts out lots of error thingies .. anyone help?