Jump to content

Problems creating a txt file using Autolisp


marc578

Recommended Posts

Hi, I am having a problem when I try to create a *.txt file and write a simple line on it.

I have the following code for my Autolisp function:

 

(defun c:prueba4()

(setq f(open "AAA.txt" "w"))

(write-line "Hi friend" f)

(close f)

)

 

I made a *.txt file previously and I have not had problems creating it (it was a similar file).

I probed on my office pc and it worked good, but when I returned to my house and tried to write the code above as a new file, I could not make it.

 

So I decided to modify and change some of the text in the file that had already working correctly, but the new modified code does not set up, I always have as result the same original text.

 

Can anyone had the same inconvenient?

 

Regards

Link to comment
Share on other sites

I'd start by adding a debugging type call to see if the file has been opened:

 

(defun c:prueba4()
(setq f(open "AAA.txt" "w"))
(prin1 (type f))
(write-line "Hi friend" f)
(close f)
)

 

 

It should display FILE at the command line

 

 

possibly a file with that name is locked open, or a symbol has been overwritten

 

-David

Link to comment
Share on other sites

Are you using an ASCII text editor, such as Notepad, to write your lisp routine?

 

When you finishing typing the routine out do you save the file before closing it?

 

Did you load the original lisp routine into AutoCAD and test it? Did it work?

Link to comment
Share on other sites

Hi, thank you for the prompt response. The program works, but the only thing is that AutoCAD create the file into the Template folder (C:\Documents and Settings\Marco\Configuración local\Datos de programa\Autodesk\AutoCAD 2007\R17.0\enu\Template), and I do not know why, because before it created the file into the My Documents folder.

 

Can anybody know why AutoCAD do that (I do not change anythink in its options)? How can tell to AutoCAD to create all the files into the My Documents folder?

Link to comment
Share on other sites

Just a hint see the double \\ in the file name as soon as you use directories with spaces in their name you can have problems Autocad will stop reading in some circumstances file names once it hits a space so always use \\. I mention it because lots of other examples here may only use a single backslash and you will wonder why it won't work when you try it.

 

Scripts in particular use a space as return button press.

 

VBA works ok just some times in lisp not working.

Link to comment
Share on other sites

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