TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on January 31, 2008, 10:59:28 AM

Title: error bad argument type: FILE nil
Post by: andrew_nao on January 31, 2008, 10:59:28 AM
can someone help me debug this im at a loss as to where the issue lies
any help is appreciated

Code: [Select]
(defun c:BLKSRC1 (/ TextFile SearchStr tmpLine endlist Opened txtfile)

(IF (setq blkdir (vl-directory-files "h:/" "*.dwg"))

(if blkdir
(progn
  (setq dirname (open "h:\\blocks.txt" "w"))
  (foreach i blkdir
    (write-line i dirname)
  ) ;end foreach
  (close dirname)
)  ;end progn
)   ;END IF BLKDIR
)   ;END IF

(defun dclmake ()
(setq dclfl (open "blk.dcl" "w"))
(write-line "blk : dialog {" dclfl)
(write-line "label = \"Search For Block...\";" dclfl)
(Write-line ": boxed_column {" dclfl)
(write-line "label = \"Enter Keyword & hit o.k.\";" dclfl)
(write-line ": edit_box {" dclfl)
(write-line "  key = \"Line1\";" dclfl)
(write-line "  label = \"Keyword:\";" dclfl)
(write-line "  edit_width = 50;" dclfl)
(write-line "  alignment = centered;" dclfl)
(write-line "  fixed_width = true;" dclfl)
(write-line "}" dclfl)
(write-line "ok_cancel;" dclfl)
(write-line "}" dclfl)
(write-line "}" dclfl)
(close dclfl)
);end dclmake


(defun edit_action1 (val)
      (if
(and
  (setq TextFile "h:\\blocks.TXT")
 
         ;(setq
    SearchStr (getstring 1 "\n Enter string to search for: ")
         (setq SearchStr val)
  )
  (setq Opened (open TextFile "r"))
) ;and
(while (setq tmpLine (read-line Opened))
   (if (vl-string-search (strcase SearchStr) (strcase tmpLine))
     (setq EndList (mapcar 'vl-filename-base (cons tmpLine endlist)))
   )
)
      (close opened)
      )
    (defun TT ()
      (if EndList
(progn
  (setq fname (open "h:\\library.lba" "w"))
  (foreach i EndList
    (write-line (strcat "h:\\slides\\" i ".sld") fname)
    (write-line (strcat "H:\\" i ".dwg") fname)
  ) ;end foreach
  (close fname)
) ;end progn
      ) ;end if

)
(dclmake)
(setq dclid (load_dialog "blk.dcl"))
(if (not (new_dialog "blk" dclid)) (exit))
(action_tile "accept" "(TT)(done_dialog)")
(action_tile "cancel" "(done_dialog)")
(action_tile "Line1" "(edit_action1 $value)")
  (start_dialog)
  (done_dialog)
  (unload_dialog dclid)
(princ)

)

Title: Re: error bad argument type: FILE nil
Post by: Mark on January 31, 2008, 12:26:55 PM
Make sure all the files listed in the code actually exist, i.e. (open "h:\\blocks.txt" "w")
Title: Re: error bad argument type: FILE nil
Post by: andrew_nao on January 31, 2008, 01:08:59 PM
Make sure all the files listed in the code actually exist, i.e. (open "h:\\blocks.txt" "w")

they do
Title: Re: error bad argument type: FILE nil
Post by: CAB on January 31, 2008, 02:25:37 PM
you should verify they do with (findfile
Title: Re: error bad argument type: FILE nil
Post by: MP on January 31, 2008, 02:28:58 PM
( the existence of a file does not guarantee one will be granted the rights to open and write to it )

:)
Title: Re: error bad argument type: FILE nil
Post by: andrew_nao on January 31, 2008, 04:30:37 PM
I got it working.
i removed some (if's (and's
and all is good now

thanks for the help all
Title: Re: error bad argument type: FILE nil
Post by: CAB on January 31, 2008, 04:54:33 PM
( the existence of a file does not guarantee one will be granted the rights to open and write to it )
How True!

Rarely happens in my small world though. :-)
I suspect a vl-catch-all-apply would handle it.