trefan123 Posted October 2, 2017 Posted October 2, 2017 (edited) Good day, I usually just hash things together. I only understand the basics. If it is possible to point me in the direction I will be most appreciated. Is it possible to bring in text from a text file where the data (not necessary numbers) is comma spaced. I use a lisp that opens notepad.exe (obtained of forum). I chose the text (size,code, description) and place it where i require for an MTO. The problem is I have to make sure there is always the correct spaces. EG: 2" (6 spaces) code (12 spaces) Description. So would rather have 2",code,description Is this possible? If so please help...lots of punching space bar. lisp ; ********************************************* ;;;--- Function to read a text file (defun getNotesPIPE() (setq returnValue "specA Loaded!") (if (setq fileName(findfile "specAPIPE.Txt")) (progn (if(setq f(open fileName "r")) (progn (while (setq lin(read-line f)) (setq notesList(append notesList(list lin))) ) ) (setq returnValue "The Spec specAPIPE.txt file could not be opened.") ) ) (setq returnValue "The Spec specAPIPE.txt file could not be found.") ) returnValue ) ;;;--- Function to save the selection in the dialog box (defun saveVars() (setq selectedItem(get_tile "notes")) ) ;;;--- Function to load the specAPIPE.txt file in notepad (defun loadNotePadPIPE() (startapp "notepad.exe" (findfile "specAPIPE.txt")) ) ;************************************************************ (defun specAPIPE() (command "style" "MTO" "monotxt" "1.8" "0.85" "" "" "" "") (command "layer" "make" "MAT-LIST" "" "" "" "") (command "osnap" "cen") ;;;--- Setup the notes list (setq notesList(list)) ;;;--- Read the notes file (setq returnValue(getNotesPIPE)) ;;;--- If the notes were not loaded ... (if(/= returnValue "specA Loaded!") ;;;--- Inform the user of an error (alert returnValue) ;;;--- Else, continue... (progn ;;;--- Load the dialog box from file (setq dcl_id (load_dialog "NOTESPIPE.dcl")) ;;;--- Find the dialog definition inside the file (if (not (new_dialog "NOTESPIPE" dcl_id)) (alert "The NOTES.DCL file could not be found!") ;;;--- Else... (progn ;;;--- Add the layout list to the dialog box (start_list "notes" 3) (mapcar 'add_list NotesList) (end_list) ;;;--- If an action event occurs, do this function (action_tile "accept" "(saveVars)(done_dialog 2)") (action_tile "edit" "(loadNotePadPIPE)") (action_tile "cancel" "(done_dialog 1)") ;;;--- Display the dialog box (setq ddiag (start_dialog)) ;;;--- Unload the dialog box (unload_dialog dcl_id) ;;;--- If the user pressed the okay button (if(= ddiag 2) (progn (setq pt1(getpoint "\n Insert Point: ")) (command "text" pt1 "0" (nth(atoi selectedItem) notesList) "") ) ) ) ) ) ) (princ) ) Edited October 2, 2017 by rkmcswain Added [CODE] tags Quote
BIGAL Posted October 3, 2017 Posted October 3, 2017 One of the easiest ways is to convert a line of csv into a list I use Lee-macs great little routine it will work with however many csv varaibles you have. ; thanks to Lee-mac for this defun (defun _csv->lst ( str / pos ) (if (setq pos (vl-string-position 44 str)) (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2)))) (list str) ) ) (setq keyvals (read-line fo)) (setq lst (_csv->lst keyvals)) or complete file as a list of list ; hard coded for file at this stage (setq fo (open "P:\\Autodesk\\lisp\\bradcodes.csv" "r")) (setq lst '()) (while (setq keyvals (read-line fo)) (setq lst (cons (_csv->lst keyvals) lst)) ) (close fo) ; str is your text value (setq str (strcat (nth 0 lst) " " (nth 1 lst) " " (nth 2 lst )) Quote
trefan123 Posted October 3, 2017 Author Posted October 3, 2017 good day, is it possible to add notes so i can understand what the code is asking / doing. Quote
BIGAL Posted October 3, 2017 Posted October 3, 2017 Instead of (setq notesList(append notesList(list lin))) you would use the Csv->lst function then use the nths to make a new string then use a cons to add all these strings into a lst. A lst -> lst2. The code is good in that it has error checking, a good starting point just needs some little bits replaced to do what you want, one that come to mind is I have a library function to write the code for a List DCL so do not have to write the dcl code every time into every routine I make, again thanks to Lee-mac pretty sure I have used his code in some of my solutions. Its like 2 lines of code and dcl works every time. This heading is one also from Alan Thompson (defun AT:ListSelect (title label height width multi lst / fn fo d item f) you can see the variables that can be passed so only one dcl but changes as required in each bit of code. But stuck on something bigger at moment will see if I can find time or some one else will jump in and modify your code. One thing I am not sure of are you implying the length of say the code is a total number of characters adding spaces as required. Using monotxt lines up. Quote
trefan123 Posted October 3, 2017 Author Posted October 3, 2017 Just to add I have this 4-----------1-------1234567890---TEE EQ SCH 40 BW A234-WPB (each dash is a space) When inserting via a chosen point via the text file it comes as one continuous text 4 1 1234567890 TEE EQ SCH 40 BW A234-WPB What I'm looking for is how to eliminate the spaces in the txt file replace with comma's (or Tabs) 4,1,1234567890,TEE EQ SCH 40 BW A234-WPB But when inserting the text the lisp will cover the spaces and still come in as normal, does not need to be one continuous text. 4 1 1234567890 TEE EQ SCH 40 BW A234-WPB one other thing, as I am trying to fathom lisp please if possible to include descriptions so i can see what is actually on the go with the code. thanks Quote
BIGAL Posted October 4, 2017 Posted October 4, 2017 Post a "specAPIPE.Txt" file and will add the code at correct points also post the dcl file else hard to test Quote
trefan123 Posted October 4, 2017 Author Posted October 4, 2017 File specAPIPE.txt ---------------------------- specAPIPE **** Text Will Be Monotext Automatically - When editing keep the text in alignment - PIPE*********** 15 1 1234567890 PIPE SMLS SCH80 A106-B 20 1 1234567890 PIPE SMLS SCH80 A106-B 25 1 1234567890 PIPE SMLS SCH80 A106-B 40 1 1234567890 PIPE SMLS SCH80 A106-B 50 1 1234567890 PIPE SMLS SCH80 A106-B 80 1 1234567890 PIPE SMLS SCH80 A106-B 100 1 1234567890 PIPE SMLS SCH80 A106-B 150 1 1234567890 PIPE SMLS SCH80 A106-B 200 1 1234567890 PIPE SMLS SCH80 A106-B 250 1 1234567890 PIPE SMLS SCH80 A106-B 300 1 1234567890 PIPE SMLS SCH80 A106-B 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.