TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Coder on April 13, 2011, 09:03:16 AM
-
Hello .
How could I divide this list to be a list or coordinate points ?
([color=red]3.09441[/color] [color=blue]3.20876[/color] 5.01197 4.31587 6.17619 2.29938 4.34473 -0.0756835 3.25095 1.8188 1.47881 1.8188 0.888771 4.57027 3.09441 3.20876)
Example .
(10 3.09441 3.20876)
So on for the rest of list .
Thanks.
-
http://lee-mac.com/groupbynum.html (http://lee-mac.com/groupbynum.html)
-
Hi,
Here's a way:
(defun flatTo2dDXF (l)
(if (cdr l)
(cons (list 10 (car l) (cadr l)) (flatTo2dDXF (cddr l)))
)
)
-
(defun foo (lst)
(if (cddr lst)
(cons (list 10 (car lst) (cadr lst)) (foo (cddr lst)))
)
)
-
Well crap. I guess I should have checked when I received the warning that someone has posted.
-
(defun test (lst / NewList)
(repeat (/ (length lst) 2)
(setq NewList (cons (list 10 (car lst) (car (setq ss (cdr lst)))) NewList) )
(setq lst (cdr lst)))
NewList
)
[color=blue](defun test (lst)
(if lst (progn
(setq New_list (cons (list 10 (car lst) (car (setq lst (cdr lst)))) New_list))
(test (cdr lst))) New_list)
)[/color]
Edit: modifed for what its worth :-)
-
(defun [color=red]_SubLists[/color] ( lst n / sublist result )
[color=green];; Group list 'lst' into sublists of length 'n'.
;;
;; Example:
;;
;; (_SubLists '(1 2 3 4 5) 2)
;;
;; => ((1 2) (3 4) (5))
;;
;; Caller's responsibility to pass valid data. Dumb data /
;; args? RAKE IN FACE.[/color]
(foreach item lst
(if (eq n (length (setq sublist (cons item sublist))))
(setq
result (cons sublist result)
sublist nil
)
)
)
(reverse
(mapcar 'reverse
(if sublist
(cons sublist result)
result
)
)
)
)
Sample use:
(mapcar
(function (lambda (sublist) (cons 10 sublist)))
([color=red]_SubLists[/color]
'( 3.09441
3.20876
5.01197
4.31587
6.17619
2.29938
4.34473
-0.0756835
3.25095
1.8188
1.47881
1.8188
0.888771
4.57027
3.09441
3.20876
)
2
)
)
=> ( (10 3.09441 3.20876)
(10 5.01197 4.31587)
(10 6.17619 2.29938)
(10 4.34473 -0.0756835)
(10 3.25095 1.8188)
(10 1.47881 1.8188)
(10 0.888771 4.57027)
(10 3.09441 3.20876)
)
-
double crap.. mine's messed up :realmad:
-
Thanks a lot guys .
Great help . Appreciated a lot .
I should have mentioned that my list is issued from a list of Coordinates from a routine .
(setq ss (entsel "\n Poly :"))
(setq pts (vlax-get (vlax-ename->vla-object (car ss)) 'Coordinates))
So the outcome of the Coordinates must be re-constructed to be re-used for another routs of lining .
Thanks a gain
-
(defun f ( l n )
(
(lambda ( g )
(if l
(cons (g l n) (f l n))
)
)
(lambda ( a b )
(if (< 0 b)
(cons (car a) (g (cdr a) (1- b)))
(setq l a a nil)
)
)
)
)
_$ (f '(1 2 3 4 5 6 7 8 9) 3)
((1 2 3) (4 5 6) (7 8 9))
-
(defun list-comp (a b / mid rslt)
(repeat (/ (length a) b)
(setq mid nil)
(repeat b
(setq mid (cons (car a) mid)
a (cdr a)
)
)
(setq rslt (cons (reverse mid) rslt))
)
(if a (reverse (cons a rslt))
(reverse rslt))
)