AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

This function will search an external text file for a list of values and import the values. It will then assign each value in the list to a variable.
First copy and paste this into Notepad :

*LIST1
1.0,2.0,3.0
*LIST2
4.0,5.0,6.0
*LIST3
7.0,8.0,9.0
*LIST4
10.0,11.0,12.0

Save this as "AFILE.TXT"
This is your point data.
Now copy and paste this into Notepad and save it as "Grab.lsp"

;CODING STARTS HERE
(defun grab (SIZA)
(setq dlist nil
size (strcat "*" SIZA)
file (findfile "AFILE.TXT")
fp (open file "r")
item (read-line fp)
)
(while item
(if (= item size)
(setq data (read-line fp)
item nil
)
(setq item (read-line fp))
)
)
(if data
(progn
(setq maxs (strlen data)
count 1
chrct 1
)
(while (< count maxs)
(if (/= "," (substr data count 1))
(setq chrct (1+ chrct))
(setq numb (atof (substr data (1+ (- count chrct)) chrct))
dlist (append dlist (list numb))
chrct 1
)
)
(setq count (1+ count))
)
(setq numb (atof (substr data (1+ (- count chrct))))
dlist (append dlist (list numb))
)
)
)
(close fp)

(mapcar 'set '(val1 val2 val3) dlist)
)
;CODING ENDS HERE

----------------------------------------
Usage :

(grab LIST1) will return (1.0 2.0. 3.0)
VAL1 will contain 1.0
VAL2 will contain 2.0
VAL3 will contain 3.0

(grab LIST4) will return (10.0 11.0. 12.0)
VAL1 will contain 10.0
VAL2 will contain 11.0
VAL3 will contain 12.0

The AutoLisp/Visual Lisp/VBA Resource Website

Copyright © 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website