Jump to content

Recommended Posts

Posted

Hi all, I have a list of coordinates and I need a function to convert pairs of them in a separate list, for example

(x1 y1 x2 y2 x3 y3 x4 y4 ....)

 >>>>  ((x1 y1) (x2 y2) (x3 y3) (x4 y4))

 

Can someone show me a way how I do this?

Posted
(defun KGA_List_Divide_2 (lst / ret)
  (repeat (/ (length lst) 2)
    (setq ret (cons (list (car lst) (cadr lst)) ret))
    (setq lst (cddr lst))
  )
  (reverse ret)
)

 

  • Like 1
Posted

One I use for 2d or 3d

 

; convert now to xyz
(defun co-ords2xy ()
(if (= xyz 2)
(progn
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)
)
)


(if (= xyz 3)
(progn
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 3))
)
)
)

)

 

 

  • Like 1
Posted

Thanks to all, actually I want to use (vlax-get obj 'Coordinates) to get coordinates  list  of a polyline  and  it gives all coordinates of x,y in one list, that is

(x1 y1 x2 y2 x3 y3 .....)

And my post was about how to split the coordintes of result of the vlax function..thanks again for your reply.

Posted
19 minutes ago, amir0914 said:

actually I want to use (vlax-get obj 'Coordinates) to get coordinates  list  of a polyline  and  it gives all coordinates of x,y in one list, that is

(x1 y1 x2 y2 x3 y3 .....)

And my post was about how to split the coordintes of result of the vlax function..thanks again for your reply.

 

Try this:

(defun _pair:coordinates (l)
  (if l
    (cons (list (car l) (cadr l)) (_pair:coordinates (cddr l)))
  )
)

Usage of the above function:

(_pair:coordinates '(1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0))

 

  • Like 1
Posted

Thanks Tharwat, I have another question, 

I can get a polyline by entsel and get area and add it at center of poyline, now, is there a way to get polyline entity by click inside it, it means without entsel (without select object)??

Posted

Yes you can.

- Getpoint

- Create a ray line.

- Then ssget with string mode "_X" for all polylines in current space.

- Then iterate through all selected polylines then sort them based on their closets intersected point to the first point you picked then first element of the list must be the polyline that surrounds the point.

 

Good luck. :) 

  • Like 1
Posted

Here is another sorry don't know author.

(if (setq plent (entsel "Pick pline"))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
)

You could also use ssget "F" pt1 pt2 in a loop keep making pt2 a little bit further out till it crosses the pline. If you know roughly the objects your looking at can make the increment as big as possible to reduce guesses.

 

(defun c:getpoly ( / pt1 pt2 ss x)
(setq inc 1.0)
(setq pt1 ( getpoint "Pick point inside pline"))
(setq pt2 (polar pt1 0.0 inc))
(setq x 0)
(while  (= (setq ss (ssget "f" (list pt1 pt2) (list (cons 0 "lwpolyline")))) nil)
(setq pt2 (polar pt2 0.0 inc))
(setq x (+ x 1)) ; just so can adjust inc can see how many guesses
)
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ss 0)))))
(princ)
)

 

I drew pline 20x 20 so inc = 1 works. If the pline has another say parallel then reduce and pick near right side to reduce guess.

  • Like 1
Posted
14 hours ago, amir0914 said:

Thanks to all, actually I want to use (vlax-get obj 'Coordinates) to get coordinates  list  of a polyline  and  it gives all coordinates of x,y in one list, that is

(x1 y1 x2 y2 x3 y3 .....)

And my post was about how to split the coordintes of result of the vlax function..thanks again for your reply.

The code I have provided does just that.

  • Like 1

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...