@vishshreevT578L wrote:
....
(defun pl:extr-pnt-from-line (_line / _p1 _p2)
(setq _line (entget _line))
....
(defun pl:extr-pnt-from-line ()
(mapcar '(lambda).........
i get the list of coordinates using the [upper] above method but i want do it using [lower approach] mapcar
I can't help but wonder why it matters what function you use, as long as you get the result you want, but still....
Using, for the initial _line argument [as in that upper function definition], the entity name of a Line, this is as close as I have been able to get using (mapcar) as an outermost function:
(mapcar
'(lambda (x)
(list (list (cadar x) (caddar x)) (list (cadadr x) (caddr (cadr x))))
); lambda
(list (vl-remove-if-not '(lambda (y) (member (car y) '(10 11))) (entget _line)))
); mapcar
However, that returns this [from a random Line I picked in a drawing]:
(((567.25 86.375) (567.25 136.0)))
which is a list containing the list I think you want of the start- and end-points' XY coordinates. It has extra parentheses around it.
I just don't think (mapcar) is the right function to do this, since it's really for mapping something such as a '(lambda) function across multiple items in a list, and it returns a new list of the results of applying that to each item in the original list. To get (mapcar) to return one thing [your desired single list, containing two XY point lists], it needs to be applied to a list containing only one item, which is why I wrapped the stripped-down start-and-end-only entity data sublist inside another (list) function. But that's also why it returns the list you want as an element inside another list. If you just change the (mapcar) function name to (apply) instead, it returns it directly as the list you want, without the extra parentheses around it. Or, if you really insist on using (mapcar) specifically, you can wrap that whole (mapcar) thing inside a (car) function, to pull the one thing out of the list that the (mapcar) part returns:
(car
(mapcar
'(lambda (x)
(list (list (cadar x) (caddar x)) (list (cadadr x) (caddr (cadr x))))
); lambda
(list (vl-remove-if-not '(lambda (y) (member (car y) '(10 11))) (entget _line)))
); mapcar
); car
But then (mapcar) is a nested function, if you can live with that. I don't guarantee there's no way to get it as an outermost function to return the list you want directly, as (apply) does, but I would suggest just using (apply) instead. If that's not acceptable, can you describe why it's essential to use (mapcar) specifically?
Kent Cooper, AIA