Jump to content

Creating a txt file Problem


mostafa badran

Recommended Posts

Hi all ,

I am having a problem when I try to create txt file like attachment

can anyone help.

thanks.

 

14-04-2014.jpg

 

(defun c:test(/ )
 (vl-load-com)
 (initget 1 "txt csv")
 (setq filtyp (getkword "\nExport Type? (txt or csv)"))
 (setq top-str "" fname (getfiled "Specify File Name" "C:\\polyline size" filtyp 1))
 (setq getarea (command "AREA" "o" pause ))
 (setq area (getvar "area"))
 (setq string (rtos area))
 (setq sttxt(strcat "Area=" string))
 (open fname "w")
[color=red] (write-line sttxt fname)
[/color]   (close fname)
 )

Link to comment
Share on other sites

From memory, (on the phone), the file argument for both write-line and close is not the string of the file name and path, but rather the return from the open function. You need to capture the (open fname "w") into a variable and use that instead of fname.

Link to comment
Share on other sites

To put in code Clint's observation:

[color=red](setq fileStream [/color](open fname "w")[color=red])[/color]
(write-line sttxt [color=#ff0000]fileStream[/color])
(close [color=#ff0000]fileStream[/color])

Link to comment
Share on other sites

From memory, (on the phone), the file argument for both write-line and close is not the string of the file name and path, but rather the return from the open function. You need to capture the (open fname "w") into a variable and use that instead of fname.

 

To put in code Clint's observation:

[color=red](setq fileStream [/color](open fname "w")[color=red])[/color]
(write-line sttxt [color=#ff0000]fileStream[/color])
(close [color=#ff0000]fileStream[/color])

Thanks guys it work perfectly now.

Thanks a lot.

Link to comment
Share on other sites

From memory, (on the phone), the file argument for both write-line and close is not the string of the file name and path, but rather the return from the open function. You need to capture the (open fname "w") into a variable and use that instead of fname.

 

To put in code Clint's observation:

[color=red](setq fileStream [/color](open fname "w")[color=red])[/color]
(write-line sttxt [color=#ff0000]fileStream[/color])
(close [color=#ff0000]fileStream[/color])

 

Thanks for the code Mircea. :-) I was struggling with the phone.

All roads lead to the Room..:D

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