Jump to content

Confusion with lambda function


gS7

Recommended Posts

Hi Guys

 

How to Create Line for coordinates from list using lambda function

Please need help for solve this

 

(defun c:test(/ lst )
     (setq lst '((1515.32 999.613 0.0) (2314.23 1081.97 0.0) (1690.57 752.536 0.0)
	  (2458.55 829.747 0.0) (1685.41 474.574 0.0) (2716.26 443.689 0.0))
     )
     (mapcar (function (lambda (x y)
		     [color="red"] (command "line" x y "")[/color] ????
		))
      lst
     )
)

Link to comment
Share on other sites

(mapcar 
 '(lambda (x y) (entmakex (list (cons 0 "LINE") (cons 10 x) (cons 11 y))))
 lst
 (append (cdr lst) (list (last lst)))
)

Or:

(mapcar 
 '(lambda (x) (entmakex (list (cons 0 "LINE") (cons 10 (car x)) (cons 11 (cadr x)))))
 (mapcar 'list lst (append (cdr lst) (list (last lst))))
)

 

 

EDIT: Or if you use LM's entmake functions, then you could just

(defun LWPoly (lst cls) ; LM
 (entmakex 
   (append 
     (list 
       (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") 
       (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls)
     )
     (mapcar (function (lambda (p) (cons 10 p))) lst)
   )
 )
)

do this:

(LWPoly lst 0)

Link to comment
Share on other sites

Grrr

 

That was awesome and i don't want to create only 3 Line Entity's for example '(1 1) '(2 2) '(3 3) Please waiting for your reply

 

If you want to create lines from a point list, you have to group the items so each one consists of 2 points (a line is defined of 2 points) :

Instead of such list

'(1 1) '(2 2) '(3 3)

you'll have to use:

(list
 '((1 1) (2 2)) ; line #1
 '((2 2) (3 3)) ; line #2
 '((3 3) (1 1)) ; line #3 (if you want to close the shape)
)

Link to comment
Share on other sites

If you want to create lines from a point list, you have to group the items so each one consists of 2 points (a line is defined of 2 points) :

Instead of such list

'(1 1) '(2 2) '(3 3)

you'll have to use:

(list
 '((1 1) (2 2)) ; line #1
 '((2 2) (3 3)) ; line #2
 '((3 3) (1 1)) ; line #3 (if you want to close the shape)
)

 

 

Grrr thank you It is helped me lot :D

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...