Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Appending to list

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
168 Views, 3 Replies

Appending to list

I have coordinates x and y in a list like this:

((0.0 208.314) (402.16 208.314) (402.16 0.0) (0.0 0.0))

and I want to take the z value out of the object (pline), which I am pulling out of the object and getting a value like so:

(240.0)

Now I want to apply it to the end of each item in the list so that it reads:

((0.0 208.314 240.0) (402.16 208.314 240.0) (402.16 0.0 240.0) (0.0 0.0 240.0))

How do I do that?
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

Command: (setq tmp (list '(2 5) '(1 5)))
((2 5) (1 5))

Command: (setq tmp2 (mapcar '(lambda (a) (list (car a) (cadr a) 240)) tmp))
((2 5 240) (1 5 240))

Hope that helps.
Tim
Message 3 of 4
Anonymous
in reply to: Anonymous

jlspartz wrote:
> I have coordinates x and y in a list like this:
>
> ((0.0 208.314) (402.16 208.314) (402.16 0.0) (0.0 0.0))
>
> and I want to take the z value out of the object (pline), which I am pulling out of the object and getting a value like so:
>
> (240.0)
>
> Now I want to apply it to the end of each item in the list so that it reads:
>
> ((0.0 208.314 240.0) (402.16 208.314 240.0) (402.16 0.0 240.0) (0.0 0.0 240.0))
>
> How do I do that?




(setq data '((0.0 208.314) (402.16 208.314) (402.16 0.0) (0.0 0.0)))


(setq z (list 240.0))


(mapcar (function(lambda (xy)(append xy z))) data)
->((0.0 208.314 240.0) (402.16 208.314 240.0)
(402.16 0.0 240.0) (0.0 0.0 240.0))




--
Message 4 of 4
Anonymous
in reply to: Anonymous

Thanks a lot! I used append and it works great!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report