Please pay attention to variables names:
Code:(setq batlst '() ... (setq batlst (append (list (list (car Vpoint) (cadr Vpoint) Xbat)) batlst))


Registered forum members do not see this ad.
Hi All,
Please help me to solve this problem.
I am trying to write a lisp routine in which it will read lines from txt file and go through the test expression and if it meets the condition it will add the lines to an existing list. Shown below is a part of the routine.
Am i doing it correctly or missing something. I am asking this because I know there should be more than 10 lines which should be added to new list but it contains only one. How?Code:(setq lst '()) (repeat (length Pdata) (setq Ppoint (nth cntr Pdata) Vpoint (list (car Ppoint) (cadr Ppoint)) Xbat (caddr Ppoint)) (setq chkoffst (distance (vlax-curve-getClosestPointTo Kproute Vpoint) Vpoint ) ) (if (<= chkoffst gap) (setq batlst (append (list (car Vpoint) (cadr Vpoint) Xbat) lst))) (setq cntr (1+ cntr)))
Thanks and Regards
Aaryan
Please pay attention to variables names:
Code:(setq batlst '() ... (setq batlst (append (list (list (car Vpoint) (cadr Vpoint) Xbat)) batlst))
Regards,
Mircea
AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3


Thank You So much Mircea
You're welcome, Aaryan!
Regards,
Mircea
AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3


Sorry Mircea I am back again with almost same problem. Am I missing something here because I am getting all list as nil.
My file is something like this
500,200,23.5,H1
200,220,23.4,H2
500,150,22.8,H3
450,250,21.9,H4
400,300,22.2,H5
600,400,23.3,H6
Please Reply.
RegardsCode:(setq Ref1lst '() Ref2lst '() Ref3lst '() Ref4lst '() Ref5lst '() Ref6lst '()) (repeat (length SBPdata) (setq SBPpoint (nth contr SBPdata);Easting, Northing and Elevation SVPpoint (list (car SBPpoint) (cadr SBPpoint));Easting and Northing SBPbat (caddr SBPpoint);Elevation Reflect (cadddr SBPpoint);could be anyone from H1, H2, H3, H4, H5 ,H6 counter 0) (if (= Reflect "H1") (setq Ref1lst (append (list SBPpoint) Ref1lst))) (if (= Reflect "H2") (setq Ref2lst (append (list SBPpoint) Ref2lst))) (if (= Reflect "H3") (setq Ref3lst (append (list SBPpoint) Ref3lst))) (if (= Reflect "H4") (setq Ref4lst (append (list SBPpoint) Ref4lst))) (if (= Reflect "H5") (setq Ref5lst (append (list SBPpoint) Ref5lst))) (if (= Reflect "H6") (setq Ref6lst (append (list SBPpoint) Ref6lst))) (setq contr (1+ contr)))
Aaryan
Again, please pay attention to the names of variables. Second, the counter should be defined when you use it, and also should be initiated outside cycle. If initiated inside cycle it will be reset each time and only the first item from list will be evaluated.
Code:(setq counter 0) (repeat (length SBPdata) (setq SBPpoint (nth counter SBPdata);Easting, Northing and Elevation SVPpoint (list (car SBPpoint) (cadr SBPpoint));Easting and Northing SBPbat (caddr SBPpoint);Elevation Reflect (cadddr SBPpoint));could be anyone from H1, H2, H3, H4, H5 ,H6 (if (= Reflect "H1") (setq Ref1lst (append (list SBPpoint) Ref1lst))) (if (= Reflect "H2") (setq Ref2lst (append (list SBPpoint) Ref2lst))) (if (= Reflect "H3") (setq Ref3lst (append (list SBPpoint) Ref3lst))) (if (= Reflect "H4") (setq Ref4lst (append (list SBPpoint) Ref4lst))) (if (= Reflect "H5") (setq Ref5lst (append (list SBPpoint) Ref5lst))) (if (= Reflect "H6") (setq Ref6lst (append (list SBPpoint) Ref6lst))) (setq counter (1+ counter)))
Regards,
Mircea
AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3
EDIT: includes building the point lisCode:(setq SBPdata '("500,200,23.5,H1" "200,220,23.4,H2" "500,150,22.8,H3" "450,250,21.9,H4" "400,300,22.2,H5" "600,400,23.3,H6") Data '((H1 "Ref1lst") (H2 "Ref2lst") (H3 "Ref3lst") (H4 "Ref4lst") (H5 "Ref5lst") (H6 "Ref6lst"))) (foreach itm SBPdata (if (setq fle (assoc (last (setq lst (read (strcat "(" (vl-string-translate "," " " itm) ")")))) Data)) (set (read (cadr fle)) (cons (list (car lst) (cadr lst)) (eval (read (cadr fle))) ))))
Last edited by pBe; 10th Jul 2012 at 07:57 am.
Aaryan, you may optimize a little the above code:
Code:(setq Ref1lst '() Ref2lst '() Ref3lst '() Ref4lst '() Ref5lst '() Ref6lst '()) (foreach SBPpoint SBPdata (setq SVPpoint (list (car SBPpoint) (cadr SBPpoint)) ;Easting and Northing SBPbat (caddr SBPpoint) ;Elevation Reflect (cadddr SBPpoint)) ;could be anyone from H1, H2, H3, H4, H5 ,H6 (cond ((= Reflect "H1") (setq Ref1lst (append (list SBPpoint) Ref1lst))) ((= Reflect "H2") (setq Ref2lst (append (list SBPpoint) Ref2lst))) ((= Reflect "H3") (setq Ref3lst (append (list SBPpoint) Ref3lst))) ((= Reflect "H4") (setq Ref4lst (append (list SBPpoint) Ref4lst))) ((= Reflect "H5") (setq Ref5lst (append (list SBPpoint) Ref5lst))) ((= Reflect "H6") (setq Ref6lst (append (list SBPpoint) Ref6lst))) ) )
Regards,
Mircea
AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3


Thanks You both for your efforts.
Regards
Aaryan


Registered forum members do not see this ad.
@pBe Please tell me how will i create a list which contains all H1, H2..seperately.
@Mircea I am still getting an empty lists.
Please help me as i am stuck only at this point.
I actually need to create seperate lists which contains easting,northing,elevation,tag.Code:(while (setq SBPinfo (read-line opnSBP)) (setq SBPdata (cons (read (strcat "(" (vl-string-translate "," " " SBPinfo) ")")) SBPdata))) (close opnSBP) (setq counter 0) (setq Ref1lst '() Ref2lst '() Ref3lst '() Ref4lst '() Ref5lst '() Ref6lst '()) Below Your codes
eg. Ref1lst should contains (500 200 23.5 H1)
Ref2lst should contains (600 300 23.4 H2)
etc..
Regards
Aaryan
Bookmarks