Autolisp OPEN command returing a nil value

I am checking an autolisp routine with BricsCAD.In this routine I am opening and writing in an excel file using open function -

(setq file(OPEN xrefpfl_nm "w"))

 but when I check the expression return value from bricscad command line, open function is

 returning nil value to file variable.Due to this

; ----- Error around expression -----

 
(CLOSE FILE)

;

;error : bad argument type ; expected FILE at [CLOSE]

error is encounterd while closing excel file using close function as value of file variable is nil.


I can't understand why open function is returning nil value to variable file in above expression.

 
Any help will be highly appreciated.



Thanks & Regards

Ajit Nikam

Comments

  • Most likely the file you are trying to open for writing has already been opened by somebody else or perhaps by you. Also it is possible that the file is read-only. You should be aware that you will only be able to write text to a file.
  • Dear Roy,

            Thanks for your comment, but I am not opening an already created file but my lisp routine is creating a new file and

     writing in it each time when i run this routine. 

  • Maybe, the folder where you want to create + write the file does not allow creating of a file ...
    Windows Vista + 7 + are very restrictive with particular folder (i.e. c:/program files/, c:(program files x86/).

    Can you specify the full path of the file you want to create here ?
    Many greetings !
  • Dear Torsten,

            I am using windows xp and I have full read and write rights of folder where I am creating an excel file.

    I am attaching a Lisp source file containing a routine named xpf-p. This routine write names of external references and their

    respective paths in a newly created excel file.This excel file will be saved in current drawing directory and name of an excel file

     will be Drawing file name + XPF.

     

    tmp.lsp

  • I have no problem with the code - I manually tested :

    : (setq dwg_nm (getvar "DWGNAME"))
    "Drawing1.dwg"
    : (setq xrefpfl_nm (strcat (vl-filename-base dwg_nm) "XPF.xls"))
    "Drawing1XPF.xls"
    : (setq file (open xrefpfl_nm "w"))
    #
    : (close file)
    nil

    Just a hint - you might not use "file" as variable name, as FILE is a built-in symbol for "file type" ... better use "fptr".

  • Hi Torsten,

        My problem get resolved as I explicitly given a path of excel file in lisp routine.

    Please find the attached modified code.I want to thanks Mr. Rakesh Rao from Bricsys India

    for the fix

    Many Thanks

    Ajit NIkam

    alisp.LSP

This discussion has been closed.