Author Topic: error bad argument type: FILE nil  (Read 5083 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
error bad argument type: FILE nil
« 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)

)


Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: error bad argument type: FILE nil
« Reply #1 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")
TheSwamp.org  (serving the CAD community since 2003)

andrew_nao

  • Guest
Re: error bad argument type: FILE nil
« Reply #2 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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: error bad argument type: FILE nil
« Reply #3 on: January 31, 2008, 02:25:37 PM »
you should verify they do with (findfile
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: error bad argument type: FILE nil
« Reply #4 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 )

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

andrew_nao

  • Guest
Re: error bad argument type: FILE nil
« Reply #5 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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: error bad argument type: FILE nil
« Reply #6 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.