muthu123 Posted December 10, 2009 Share Posted December 10, 2009 Dear all, I am developing one project for my cencern, in this project i have so many details in a list format. I want to write all the lists in a text file as a organized manner and get it back as a list whenever required. Please try forme. my mail. mkumar@mabanisteel.com Quote Link to comment Share on other sites More sharing options...
MSasu Posted December 10, 2009 Share Posted December 10, 2009 Use PRINT statement with the list as argument to record it in the data file. After call READ-LINE to retrieve it from file, respectively READ to evaluate the string into a list. Quote Link to comment Share on other sites More sharing options...
muthu123 Posted December 10, 2009 Author Share Posted December 10, 2009 Dear msasu, Thank you so much. I wasted full day for this task. I didn't use both the function till now which make me mad. Anyhow thank you so much for your immediate response. Can you explain in detail about that functions. Quote Link to comment Share on other sites More sharing options...
MSasu Posted December 10, 2009 Share Posted December 10, 2009 You are welcomed! The below examples may help you: To record a list into a text file: (setq TargetFile (open "c:\\test_20091210.txt" "w")) ;open file to write (princ '(1 2 3 4) TargetFile) ;record the list into file (close TargetFile) ;close the file To retrieve that list from the file: (setq SourceFile (open "c:\\test_20091210.txt" "r")) ;open file to read (setq FileLine (read-line SourceFile)) ;read file content (one line in this case) (close SourceFile) ;close the file (setq theListFromFile (read FileLine)) ;evaluate the string into a list For more and better explanations may use AutoLISP’s help. Regards, Quote Link to comment Share on other sites More sharing options...
muthu123 Posted December 10, 2009 Author Share Posted December 10, 2009 can you give me your mail ID to contact you if i face any problem in my task. my mail Id mkumar@mabanisteel.com Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 10, 2009 Share Posted December 10, 2009 This should help you for writing to files: http://www.cadtutor.net/forum/showthread.php?p=271366&highlight=AT%3AWRITETOFILE#post271366 Quote Link to comment Share on other sites More sharing options...
MSasu Posted December 11, 2009 Share Posted December 11, 2009 can you give me your mail ID to contact you if i face any problem in my task.my mail Id You will get better support if continue to post on forum – there are many great programmers that can help you and a lot of good approaches for each issue to choose from. Also, is a good practice to avoid posting in clear your e-mail address since this sound like an invitation to spammers. For the case when you cannot avoid doing so, just spell it like: “user at domain dot extension” at list this will avoid automatically parsing. Quote Link to comment Share on other sites More sharing options...
muthu123 Posted December 14, 2009 Author Share Posted December 14, 2009 This should help you for writing to files:http://www.cadtutor.net/forum/showthread.php?p=271366&highlight=AT%3AWRITETOFILE#post271366 Thank you so much Mr.alanjt. Sincerely, Muthu Kumar Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 14, 2009 Share Posted December 14, 2009 Thank you so much Mr.alanjt. Sincerely, Muthu Kumar Happy to help. Quote Link to comment Share on other sites More sharing options...
muthu123 Posted December 21, 2009 Author Share Posted December 21, 2009 Dear friends, can you help me to modify this following lisp (defun save_input_as_a_text_file_from_list () (setq input_text_file (strcat path_input_endwall "/endwall.txt")) (setq file_descr (open input_text_file "w")) (close file_descr) (setq list_type_variables (list "main_input_building_details" "clear_span_dialog_details" "left_end_column_size" )) (setq file_descr (open input_text_file "a")) (setq i 0) (repeat (length list_type_variables) (write-line (nth i list_type_variables) file_descr) (princ (eval (read (nth i list_type_variables))) file_descr) (princ "\n" file_descr) (setq i (1+ i)) ) (close file_descr) ) I need a text file like this firstline will be varible name nextline will be the whole list main_input_building_details (("frame_type" "typical_endwall" "endwall_type_left" "endwall_girt_type_left" "corner_column_left_endwall" "endwall_column_spacings_left" "bay_spacings_sidewall" "building_length" "building_width" "eave_height" "expansion_joint" "gen_block_wall_ht") ("clear_span" "typical_endwall_yes" "bearing_frame_left" "by_pass_left" "306" "5@6000" "10@6000" "60000" "30000" "6000" "0" "2500")) clear_span_dialog_details (("building_width" "ridge_distance" "frame_profile" "eave_height_left" "ridge_slope_left" "girt_spacings_left" "purlin_spacings_left" "eave_height_right" "ridge_slope_right" "girt_spacings_right" "purlin_spacings_right") ("30000" "15000" "symmetrical" "6000" "1" "10@1000" "10@1500" "6000" "1" "10@1000" "10@1500")) left_end_column_size ("Ipea-200" "Ipea-200" "Ipea-200" "Ipea-200" "Ipea-200" "Ipea-200") But my lisp is removing the double quote inside the list and writing like this as a text file. main_input_building_details ((frame_type typical_endwall endwall_type_left endwall_girt_type_left corner_column_left_endwall endwall_column_spacings_left bay_spacings_sidewall building_length building_width eave_height expansion_joint gen_block_wall_ht) (clear_span typical_endwall_yes bearing_frame_left by_pass_left 306 5@6000 10@6000 60000 30000 6000 0 3000)) clear_span_dialog_details ((building_width ridge_distance frame_profile eave_height_left ridge_slope_left girt_spacings_left purlin_spacings_left eave_height_right ridge_slope_right girt_spacings_right purlin_spacings_right) (30000 15000 symmetrical 6000 1 10@1000 10@1500 6000 1 10@1000 10@1500)) left_end_column_size (Ipea-200 UB-203 UB-203 UB-203 Ipea-200 Ipea-200) Quote Link to comment Share on other sites More sharing options...
MSasu Posted December 21, 2009 Share Posted December 21, 2009 Just remove that EVAL from record procedure: (princ (eval (read (nth i list_type_variables))) file_descr) Quote Link to comment Share on other sites More sharing options...
muthu123 Posted December 21, 2009 Author Share Posted December 21, 2009 No msasu. I need the value of that variable to be written. I hope we have to use eval function. Am i correct? otherwise it will print the variable name only. Quote Link to comment Share on other sites More sharing options...
MSasu Posted December 21, 2009 Share Posted December 21, 2009 Not sure why you are parsing the lists instead of recording it directly – the below code is producing for me the result that you expect: (setq Var1st "1" Var2nd "2" Var3rd "3") (setq theFile (open "C:\\string_list_test.txt" "w")) (prin1 (list Var1st Var2nd Var3rd) theFile) (close theFile) Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 21, 2009 Share Posted December 21, 2009 Use Print instead of Write-Line. print(print [expr [file-desc]]) This function is the same as prin1, except it prints a newline character before expr, and prints a space following expr. Arguments expr A string or AutoLISP expression. Only the specified expr is printed; no newline or space is included. Prints an expression to the command line, or writes an expression to an open file Prints an expression to the command line, or writes an expression to an open file 144 | AutoLISP Reference file-desc A file descriptor for a file opened for writing. Return Values The value of the Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 21, 2009 Share Posted December 21, 2009 Examples for you to look over: ;; Writing the File (defun c:list_write (/ f lst1 lst2) (vl-load-com) (if (setq f (getfiled "Output" "" "txt" 1)) (progn (setq lst1 '("A" "B" "C" "D" "E" "F") lst2 '("1" "2" "3" "4" "5" "6")) (setq f (open f "w")) (foreach x '(lst1 lst2) (write-line (vl-princ-to-string x) f) (write-line (vl-prin1-to-string (eval x)) f)) (close f))) (princ)) ;; Reading the File back (defun c:list_read (/ f var lst) (if (setq f (getfiled "Input" "" "txt" 16)) (progn (setq f (open f "r")) (while (and (setq var (read-line f)) (setq lst (read-line f))) (set (read var) (read lst))) (close f))) (princ)) Of course, you could use "print", or "prin1" over "vl-princ-to-string" and "vl-prin1-to-string", but thats just me Quote Link to comment Share on other sites More sharing options...
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.