inzy Posted October 12, 2010 Posted October 12, 2010 Hey all, I didn't write this batch lisp but I've been using it for a long time. Recently, the lisp hasn't been working. The error I get when I try to run is, "; error: bad argument type: consp nil". I am not sure what changed to produce this error. Please help me get this working again. Thanks in advance. (defun c:bpp () (setq flist (vl-sort (vl-directory-files "" "*.dwg") '<)) (setq listlength (- (length flist) 1)) (setq opf (open "flist.scr" "w")) (write-line "expert" opf) (write-line "5" opf) (if (= 0 (getvar "SDI")) (progn (write-line "close" opf) (if (/= 0 (getvar "dbmod"))(write-line "y" opf)) (setq count 0) (while (nth count flist) (write-line "open" opf) (write-line (strcat (chr 34)(nth count flist)(chr 34)) opf) (write-line "pdf" opf) (write-line "close" opf) (write-line "y" opf) (setq count (1+ count)) );end of while );end of if not single document mode This writes close first then loops ;through open print close for each document. (progn (write-line "open" opf) (if (/= 0 (getvar "dbmod"))(write-line "y" opf)) (setq count 0) (while (nth count flist) (write-line (strcat (chr 34)(nth count flist)(chr 34)) opf) (write-line "pdf" opf) (if (/= count listlength) (write-line "open" opf)) (if (/= count listlength) (write-line "y" opf)) (setq count (1+ count)) );end of while loop that writes to the open file );end of if SDI is not 0, then don't write close first );end of main if statement, if sdi is 0 or 1 (write-line "expert" opf) (write-line "0" opf) (close opf) (princ) (command "script" "flist.scr") ) Quote
Lee Mac Posted October 12, 2010 Posted October 12, 2010 Would this do what you want? http://www.cadtutor.net/forum/showthread.php?48570-Script-Writer Quote
inzy Posted October 12, 2010 Author Posted October 12, 2010 Would this do what you want? http://www.cadtutor.net/forum/showthread.php?48570-Script-Writer Thanks Lee Mac, I've been using scripts to do my tasks lately. I am still curious why this lisp no longer works. I've used it so long and it worked great for what I needed to get done. I like to share it with co-workers and it was easy to set them up to use it. Quote
Lee Mac Posted October 13, 2010 Posted October 13, 2010 Assuming the scripting parts are correct, bear in mind that (nth <i> nil) will produce: ; error: bad argument type: consp nil So perhaps no Drawing files are being found. Quote
inzy Posted October 13, 2010 Author Posted October 13, 2010 You're right.. (setq flist (vl-sort (vl-directory-files "" "*.dwg") '<)) My problem is in this line or a setting in AutoCAD. It's not making the file list from the current(working) directory that I opened my drawing from. It doesn't seem to find any drawings. I wonder what directory it looks for dwg's and why? Quote
Lee Mac Posted October 13, 2010 Posted October 13, 2010 You could use something like this perhaps: (vl-directory-files nil "*.dwg") PS> Why use different scripts for different settings of SDI mode? Why not just open/close each drawing either anyway? Quote
inzy Posted October 13, 2010 Author Posted October 13, 2010 Yeah, I tried nil. Also eliminated the vl-sort; both with the same result. I really think it's looking in a different directory than it should. I wish I knew what directory and why. With SDI on, I thought you can't close a drawing. This would make a different script, would it not? Quote
Lee Mac Posted October 13, 2010 Posted October 13, 2010 Yeah, I tried nil. Also eliminated the vl-sort; both with the same result. I really think it's looking in a different directory than it should. I wish I knew what directory and why. The working directory can be known using: (getvar 'DWGPREFIX) With SDI on, I thought you can't close a drawing. This would make a different script, would it not? Apologies, I don't use SDI mode, hence my comment was derived from my thoughts on its effect, I should've experimented first .. Quote
inzy Posted October 13, 2010 Author Posted October 13, 2010 (edited) Thanks Lee Mac! I managed to get it working again. This was a good learning experience. I appreciate all the help! Edited October 13, 2010 by inzy Quote
alanjt Posted October 13, 2010 Posted October 13, 2010 If you are using a lot of scripts, you should also look into Autodesk's ScriptPro or AutoScript (for 64-bit machines) and both are free. 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.