SCaldeira Posted April 3, 2012 Posted April 3, 2012 Somebody can give me an example of a lisp file that take the value of a variable and create a txt file on a especific place defining by the user, with 10 lines in each one of them begins with what is in the variable, followed by a text already done. Thanks for your help. Quote
pBe Posted April 3, 2012 Posted April 3, 2012 What is the variable value? -String -Real -Integer -Point list Quote
Tiger Posted April 3, 2012 Posted April 3, 2012 Is this an assignment of some sort? It sounds like it from your post... Quote
pBe Posted April 3, 2012 Posted April 3, 2012 the variable value is String. Check And this? with 10 lines in each one of them begins with what is in the variable, followed by a text already done. Is that after 10 lines you'll be prompted for another file name? Show us an example of the resulting text file Is this an assignment of some sort? It sounds like it from your post... Quote
SCaldeira Posted April 3, 2012 Author Posted April 3, 2012 an example: I put "ABC" into a variable and the result is a text file with 10 lines: ABCtextexampleline1 ABCtextexampleline2 ABCtextexampleline3 ABCtextexampleline4 ..... ABCtextexampleline10 Quote
pBe Posted April 3, 2012 Posted April 3, 2012 an example: I put "ABC" into a variable and the result is a text file with 10 lines:ABCtextexampleline1...... I understand that SCaldeira, What i'm trying to get from you to tell us is what's the source of this ABCexampleLine1 etc....? Say you already have ABC, where would the other 10 values comes from? is it from a Selected Text/Mtext entity? And right after you have the 10 string values, then what happens next? does the progam ends when you reach 10 lines and start over again? You need to be clear so this thread wont drag-on to 5 pages and what-not. Quote
SCaldeira Posted April 3, 2012 Author Posted April 3, 2012 The text already exists and is always the same but different from line to line. Quote
MSasu Posted April 3, 2012 Posted April 3, 2012 You mean that you are looking to access the file and append a suffix string to each line? Regards, Mircea Quote
MSasu Posted April 3, 2012 Posted April 3, 2012 The title of the thread ask to create a file... So, you should: open the file in read mode - OPEN, parse each line until the end of file (nil) - WHILE & READ-LINE, append the suffix to each line - STRCAT, store those line into a list - APPEND, when done, close the file - CLOSE, open the file in write mode - OPEN, parse the said list and record the items to file - FOREACH & WRITE-LINE, when done, close the file; this will save it also - CLOSE, Regards, Mircea Quote
pBe Posted April 3, 2012 Posted April 3, 2012 The text already exists and is always the same but different from line to line. You mean that you are looking to access the file and append a suffix string to each line? Now it makes sense. I guess i'm asking the wrong questions then. Quote
MSasu Posted April 3, 2012 Posted April 3, 2012 @SCaldeira: You're welcome! If you will encounter issues with this code, just post here what you have written for further help. Don't forget to close the file when finnished accessing it. Regards, Mircea Quote
MSasu Posted April 3, 2012 Posted April 3, 2012 I guess i'm asking the wrong questions then. I was also confused by the title of the thread. Regards, Mircea Quote
SCaldeira Posted April 3, 2012 Author Posted April 3, 2012 I tried to do so but does not work. Can you help me find the error? lisp code: (defun C:d2 ( ) (setq DCL (load_dialog "d2")) ; (new_dialog "CARTA2" DCL) (action_tile "IDCarta" "(setq NCarta (get_tile \"IDCarta\"))") (action_tile "25M" "(setq Escala 25000)") (action_tile "10M" "(setq Escala 10000)") (action_tile "5M" "(setq Escala 5000)") (action_tile "accept" "(done_dialog)") ; (action_tile "cancel" "(setq NCarta nil)(done_dialog)") (start_dialog) ; Inicia (unload_dialog DCL) ; ;---------------------------------- (setq lspdir "E:\\CartasTXT\\") (setq txtfile (strcat lspdir "notes")) (setq fichTXT (open (getfiled "Defina o nome e a localização do ficheiro TXT da carta." txtfile "txt" 1) "w")) (prin1 (type fichTXT)) (if (= Escala 25000) ( (write-line (strcat NCarta "-your choice is 25000, line1") fichTXT) (write-line (strcat NCarta "-your choice is 25000, line2") fichTXT) (write-line (strcat NCarta "-your choice is 25000, line3") fichTXT) ;......an so on (close fichTXT) )) ;---------------------------------- (if (= Escala 10000) ( (write-line (strcat NCarta "-your choice is 10000, line1") fichTXT) (write-line (strcat NCarta "-your choice is 10000, line2") fichTXT) (write-line (strcat NCarta "-your choice is 10000, line3") fichTXT) ;......an so on (close fichTXT) )) ;---------------------------------- (if (= Escala 5000) ( (write-line (strcat NCarta "-your choice is 5000, line1") fichTXT) (write-line (strcat NCarta "-your choice is 5000, line2") fichTXT) (write-line (strcat NCarta "-your choice is 5000, line3") fichTXT) ;......an so on (close fichTXT) )) ) dcl code: /* Dialog Box: carta2 */ CARTA2: dialog { label = "Escala da Carta"; :radio_button {key = "25M"; label = "Carta 1:25000"; } :radio_button {key = "10M"; label = "Carta 1:10000"; } :radio_button {key = "5M"; label = "Carta 1:5000"; } spacer; :edit_box { label = "ID da Carta "; key = "IDCarta"; width = 7; } spacer; ok_cancel; } Quote
MSasu Posted April 3, 2012 Posted April 3, 2012 I will take a look on your code; meantime please edit your last post to add code brackets. Regards, Mircea Quote
MSasu Posted April 3, 2012 Posted April 3, 2012 I have rewritted the code with COND. Also is better to validate if user supplied a name for the new file prior to attempt to access it. (defun C:d2 ( / [color=red]DCL NCarta Escala lspdir txtfile fichTXT[/color] ) (setq DCL (load_dialog "d2")) ; (new_dialog "CARTA2" DCL) (action_tile "IDCarta" "(setq NCarta (get_tile \"IDCarta\"))") (action_tile "25M" "(setq Escala 25000)") (action_tile "10M" "(setq Escala 10000)") (action_tile "5M" "(setq Escala 5000)") (action_tile "accept" "(done_dialog)") ; (action_tile "cancel" "(setq NCarta nil)(done_dialog)") (start_dialog) ; Inicia (unload_dialog DCL) ; ;---------------------------------- (setq lspdir "E:\\CartasTXT\\") (setq txtfile (strcat lspdir "notes")) [color=red] (if (and NCarta[/color] [color=red] Escala[/color] [color=red] (setq fichTXT (getfiled "Defina o nome e a localização do ficheiro TXT da carta."[/color] [color=red] txtfile "txt" 1)))[/color] [color=red] (progn[/color] (setq fichTXT (open fichTXT "w")) (prin1 (type fichTXT)) [color=red] (cond[/color] ((= Escala 25000) (write-line (strcat NCarta "-your choice is 25000, line1") fichTXT) (write-line (strcat NCarta "-your choice is 25000, line2") fichTXT) (write-line (strcat NCarta "-your choice is 25000, line3") fichTXT) ;......an so on ) ((= Escala 10000) (write-line (strcat NCarta "-your choice is 10000, line1") fichTXT) (write-line (strcat NCarta "-your choice is 10000, line2") fichTXT) (write-line (strcat NCarta "-your choice is 10000, line3") fichTXT) ;......an so on ) ((= Escala 5000) (write-line (strcat NCarta "-your choice is 5000, line1") fichTXT) (write-line (strcat NCarta "-your choice is 5000, line2") fichTXT) (write-line (strcat NCarta "-your choice is 5000, line3") fichTXT) ;......an so on ) [color=red] )[/color] [color=red] )[/color] [color=red] )[/color] (close fichTXT) ) If you want to use IF then should not forget to envelop the expressions with PROGN: (if (= Escala 10000) [color=red] (progn[/color] (write-line (strcat NCarta "-your choice is 10000, line1") fichTXT) (write-line (strcat NCarta "-your choice is 10000, line2") fichTXT) (write-line (strcat NCarta "-your choice is 10000, line3") fichTXT) ;......an so on [color=red] )[/color] ) Also, I will let the CLOSE call outside "conditioned" code to ensure that the file is closed. Regards, Mircea Quote
SCaldeira Posted April 3, 2012 Author Posted April 3, 2012 That's right. Fantastic. Thank you Mircea. :D :D Quote
Recommended Posts
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.