Jump to content

Recommended Posts

Posted

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")
)

Posted

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.

Posted

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?

Posted

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?

Posted

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?

Posted
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 ..

Posted (edited)

Thanks Lee Mac! I managed to get it working again. This was a good learning experience. I appreciate all the help!

Edited by inzy

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...