RepCad Posted February 4, 2020 Posted February 4, 2020 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? Quote
Roy_043 Posted February 4, 2020 Posted February 4, 2020 (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) ) 1 Quote
BIGAL Posted February 5, 2020 Posted February 5, 2020 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)) ) ) ) ) 1 Quote
RepCad Posted February 8, 2020 Author Posted February 8, 2020 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. Quote
Tharwat Posted February 8, 2020 Posted February 8, 2020 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)) 1 Quote
RepCad Posted February 8, 2020 Author Posted February 8, 2020 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)?? Quote
Tharwat Posted February 8, 2020 Posted February 8, 2020 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. 1 Quote
marko_ribar Posted February 8, 2020 Posted February 8, 2020 16 minutes ago, amir0914 said: 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)?? You can try something similar to this also... http://www.theswamp.org/index.php?topic=55509.msg596797#msg596797 1 Quote
BIGAL Posted February 9, 2020 Posted February 9, 2020 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. 1 Quote
Roy_043 Posted February 9, 2020 Posted February 9, 2020 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. 1 Quote
Recommended Posts
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.