TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cjw on April 29, 2009, 04:09:51 AM
-
(setq LST1 '(((1371.24 720.75 0.0) . 100.408)
((1030.31 740.794 0.0) . 80.7133)
((1030.31 740.794 0.0) . 40.6777)
((655.957 393.364 0.0) . 92.1824)
((655.957 393.364 0.0) . 53.9207)
((527.273 794.245 0.0) . 116.764)
)
)
(setq LST2 '(((1371.24 720.75 0.0) . (100.408))
((1030.31 740.794 0.0) . (80.7133 40.6777))
((655.957 393.364 0.0) . (92.1824 53.9207))
((527.273 794.245 0.0) . (116.764))
)
)
How to realize LST1->LST2?
Thanks,it's too hard for me,I think there are good boys can help me here.
-
cjw, are you sure you want the dot in there on the output? Notice that the output from your setq lst2 strips the dots:
(((1371.24 720.75 0.0) 100.408)
((1030.31 740.794 0.0) 80.7133 40.6777)
((655.957 393.364 0.0) 92.1824 53.9207)
((527.273 794.245 0.0) 116.764)
)
That said, the following code will return the same thing as your setq lst2:
(defun CondenseList(lst1 / lstsbypoint rtlist)
(setq
lstsbypoint (mapcar
(function
(lambda(ptinfo1)
(vl-remove-if-not
(function
(lambda(pt)
(equal (car pt) (car ptinfo1))
)
)
lst1
)
)
)
lst1
)
rtlist (mapcar
(function
(lambda(x)
(CombineCDRs x)
)
)
lstsbypoint
)
rtlist (removeduplicates rtlist)
)
)
(defun CombineCDRs(lst / rtlist)
(setq rtlist
(cons (caar lst)
(mapcar
(function
(lambda(pts /)
(setq rtlist (cons (cdr pts) rtlist))
)
)
lst
)
)
rtlist (vl-list*
(car rtlist)
(if (= 1 (length (cdr rtlist)))
(cadr rtlist)
(reverse (last rtlist))
)
)
)
)
;;This removeduplicates code came from a post by MP
(defun RemoveDuplicatesAux ( x )
(cond
((vl-position x index))
((null (setq index (cons x index))))
)
)
(defun RemoveDuplicates ( lst / index )
(vl-remove-if
'RemoveDuplicatesAux
lst
)
)
And running this with your lst1 returns:
(setq temp (condenselist lst1))
(((1371.24 720.75 0.0) 100.408)
((1030.31 740.794 0.0) 80.7133 40.6777)
((655.957 393.364 0.0) 92.1824 53.9207)
((527.273 794.245 0.0) 116.764)
)
-
mkweaver,
Good job!
Thank you vvvvvvery much!!!!
-
You are welcome.