List manipulation

List manipulation

Muhammed.OPERA
Advisor Advisor
911 Views
5 Replies
Message 1 of 6

List manipulation

Muhammed.OPERA
Advisor
Advisor

Hi everyone,

I faced a problem, i have a list of coordinates obtained from:

(setq Clst
(vlax-safearray->list (vlax-variant-value (vla-get-coordinates (car A) ) ) )
)

A : is a previously predefined variable from (ssget ) Function.

Now, Clst is a list with no. of coordinates depends on the number of vertex of the selected polyline.

i can say that the No. of points: 

(setq Pno (fix (/ (Length Clst) 2)))

I wanna now store every couple of those coordinates from Clst List in separate lists to use after that.

I tried to use repeat function with the number of points calculated, and store 2 coordinates in one list, but

using (vl-remove ) function deletes the values i stored in sublists from the Coordinates list every time it presents in the list, so it's not working.

What is my best option i can use?

Thanks 🙂


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Accepted solutions (1)
912 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You can try one of these functions :

Recursive:

(defun 2dCoordsToPoints (lst)
  (if lst
    (cons (list (car lst) (cadr lst)) (2dCoords2Pts (cddr lst)))
  )
)

Iterative:

(defun 2dCoordsToPoints (lst / res)
  (while lst
    (setq res (cons (list (car lst) (cadr lst)) res)
	  lst (cddr lst)
    )
  )
  (reverse res)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6

_gile
Consultant
Consultant

Oopss!...

Recursive:

(defun 2dCoords2Pts (lst)
  (if lst
    (cons (list (car lst) (cadr lst)) (2dCoords2Pts (cddr lst)))
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 6

Muhammed.OPERA
Advisor
Advisor

Hi @_gile

Thanks for that, that helped and gave me the chance to understand/learn list manipulation functions.


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Message 5 of 6

_gile
Consultant
Consultant

List manipulation begins with the fundamental functions: car, cdr and cons.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 6

Muhammed.OPERA
Advisor
Advisor

Yup, i have learned that now.


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes