EricDevault Posted February 21, 2018 Posted February 21, 2018 I have a 'while' loop that adds what was entered in the command line to a list each time it loops. Then I would like to get the sum of all the numbers in the list. I am pretty confident that this should work: (setq CLength1 (apply '+ (list lst))) But I get this error on the command line: ; error: bad argument type: numberp: (36 36 36 36) Full 'while' code: (while (progn (initget "U") (setq d (getdist (strcat "\Distance to next Vert Strap (Enter when done; U to Undo)")))) (setq lst (cons (fix d) lst)) (cond ((= d "U") (command "._undo" "._back")) ((/= d 0) (progn (command "._offset" (/ d 12.) s "_non" (polar (cdr (assoc 10 (entget s))) 0. 1.) "" ) (if (not (eq s (setq s (entlast)))) (progn (setq p1 (cdr (assoc 10 (entget s))) p2 (cdr (assoc 11 (entget s))) pt (if (< (cadr p1) (cadr p2)) p1 p2 ) ) (setq dx1 (car p1) ;ent x value dx2 (cadr p1) ;ent y value dx3 (caddr p1) ;ent z value dd1 (+ dx1 (/ d 12)) ;dimension distance sdx (- dx1 (/ d 12)) ;start point x dmx (/ (+ dd1 dx1) 2) ;middle ) (if (>= d 18) (setq doff -1.6) (setq doff -3.2) ) (entmake (list (cons 0 "DIMENSION") (cons 100 "AcDbEntity") (cons 67 0) (cons 8 "DIMBAD") (cons 100 "AcDbDimension") (cons 10 (trans (list dd1 doff 0.) 1 0)) (cons 11 (trans (list dmx doff 0.) 1 0)) (cons 12 (list 0. 0. 0.)) (cons 70 33) (cons 1 "") (cons 71 5) (cons 72 1) (cons 41 1.0) (cons 52 0) (cons 53 0) (cons 54 0) (cons 3 "TEMPLATE_DRAWING") (cons 100 "AcDbAlignedDimension") (cons 13 (trans (list sdx 0. 0.) 1 0)) (cons 14 (trans (list dx1 0. 0.) 1 0)) (cons 15 (list 0. 0. 0.)) (cons 16 (list 0. 0. 0.)) )) ) ) ) ))) (setq CLength1 (apply '+ (list lst))) (princ CLength1) Quote
satishrajdev Posted February 21, 2018 Posted February 21, 2018 Try it (setq CLength1 (apply '+ lst)) Whole Code : (while (progn (initget "U") (setq d (getdist (strcat "\Distance to next Vert Strap (Enter when done; U to Undo)" ) ) ) ) (setq lst (cons (fix d) lst)) (cond ((= d "U") (command "._undo" "._back")) ((/= d 0) (progn (command "._offset" (/ d 12.) s "_non" (polar (cdr (assoc 10 (entget s))) 0. 1.) "" ) (if (not (eq s (setq s (entlast)))) (progn (setq p1 (cdr (assoc 10 (entget s))) p2 (cdr (assoc 11 (entget s))) pt (if (< (cadr p1) (cadr p2)) p1 p2 ) ) (setq dx1 (car p1) ;ent x value dx2 (cadr p1) ;ent y value dx3 (caddr p1) ;ent z value dd1 (+ dx1 (/ d 12)) ;dimension distance sdx (- dx1 (/ d 12)) ;start point x dmx (/ (+ dd1 dx1) 2) ;middle ) (if (>= d 18) (setq doff -1.6) (setq doff -3.2) ) (entmake (list (cons 0 "DIMENSION") (cons 100 "AcDbEntity") (cons 67 0) (cons 8 "DIMBAD") (cons 100 "AcDbDimension") (cons 10 (trans (list dd1 doff 0.) 1 0)) (cons 11 (trans (list dmx doff 0.) 1 0)) (cons 12 (list 0. 0. 0.)) (cons 70 33) (cons 1 "") (cons 71 5) (cons 72 1) (cons 41 1.0) (cons 52 0) (cons 53 0) (cons 54 0) (cons 3 "TEMPLATE_DRAWING") (cons 100 "AcDbAlignedDimension") (cons 13 (trans (list sdx 0. 0.) 1 0)) (cons 14 (trans (list dx1 0. 0.) 1 0)) (cons 15 (list 0. 0. 0.)) (cons 16 (list 0. 0. 0.)) ) ) ) ) ) ) ) ) (setq CLength1 (apply '+ lst)) (princ (rtos lst 2 0)) ; Add precision here Quote
EricDevault Posted February 21, 2018 Author Posted February 21, 2018 Try it (setq CLength1 (apply '+ lst)) Whole Code : (while (progn (initget "U") (setq d (getdist (strcat "\Distance to next Vert Strap (Enter when done; U to Undo)" ) ) ) ) (setq lst (cons (fix d) lst)) (cond ((= d "U") (command "._undo" "._back")) ((/= d 0) (progn (command "._offset" (/ d 12.) s "_non" (polar (cdr (assoc 10 (entget s))) 0. 1.) "" ) (if (not (eq s (setq s (entlast)))) (progn (setq p1 (cdr (assoc 10 (entget s))) p2 (cdr (assoc 11 (entget s))) pt (if (< (cadr p1) (cadr p2)) p1 p2 ) ) (setq dx1 (car p1) ;ent x value dx2 (cadr p1) ;ent y value dx3 (caddr p1) ;ent z value dd1 (+ dx1 (/ d 12)) ;dimension distance sdx (- dx1 (/ d 12)) ;start point x dmx (/ (+ dd1 dx1) 2) ;middle ) (if (>= d 18) (setq doff -1.6) (setq doff -3.2) ) (entmake (list (cons 0 "DIMENSION") (cons 100 "AcDbEntity") (cons 67 0) (cons 8 "DIMBAD") (cons 100 "AcDbDimension") (cons 10 (trans (list dd1 doff 0.) 1 0)) (cons 11 (trans (list dmx doff 0.) 1 0)) (cons 12 (list 0. 0. 0.)) (cons 70 33) (cons 1 "") (cons 71 5) (cons 72 1) (cons 41 1.0) (cons 52 0) (cons 53 0) (cons 54 0) (cons 3 "TEMPLATE_DRAWING") (cons 100 "AcDbAlignedDimension") (cons 13 (trans (list sdx 0. 0.) 1 0)) (cons 14 (trans (list dx1 0. 0.) 1 0)) (cons 15 (list 0. 0. 0.)) (cons 16 (list 0. 0. 0.)) ) ) ) ) ) ) ) ) (setq CLength1 (apply '+ lst)) (princ (rtos lst 2 0)) ; Add precision here Yup, that's it! Every example saw said to call out the list as (list lst) not sure why. But anyway thank you Quote
satishrajdev Posted February 22, 2018 Posted February 22, 2018 When you are adding (setq lst (cons (fix d) lst)) at that time itself you are defining lst variable as list already then no need to add (list lst) again. Quote
Lee Mac Posted February 22, 2018 Posted February 22, 2018 Instead of constructing the list, you could perform the summation directly - e.g. replace: (setq lst (cons (fix d) lst)) With: (setq CLength1 (+ (cond (CLength1) (0)) (fix d))) Quote
pBe Posted February 22, 2018 Posted February 22, 2018 Instead of constructing the list, you could perform the summation directly My thoughts exactly. 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.