Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
Hi all,
I'm after a LISP that will connect the center of circles with 3D poly line.
I found THIS solution by DannyNL, but it connects it in a rather chaotic manner:
What I actually need is this:
It stars looking on the X-axis going to + and only if there are no more circles it goes up&right, then starts going on the X-axis towards 0 and so on.
Ehhh... Trying to think of it from a mathematical standpoint. If nil on X then Y- to obj. 🤔
You meight be looking for greedy algorithm... So there is one implemented in TSP (Travelling Salesman Problem) posted here in download section... You have to strip it from *.arx processing or just use grid option when you start routine... But all in all, I doubt it'll go X+X+X+...X ; -X-X-X-...-X... It'll search for closest point or center of circle in every step from starting point to end one and at the end it'll make closed polyline that don't make crossings... Link for download is here : https://www.cadtutor.net/forum/files/file/42-tspzip-travelling-salesman-problem-autolisp/
hey there,
check the following
(defun c:meander (/ circle_sset center_list y_coordinate_list unique_y_list 3dpoly_vertices_list)
(if (setq circle_sset (ssget '((0 . "circle"))))
(progn
(setq center_list (mapcar '(lambda (circle) (vlax-get circle 'center)) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex circle_sset)))))
y_coordinate_list (vl-sort (mapcar 'cadr center_list) '<)
y_fuzz 1
)
(foreach _y y_coordinate_list (if (not (vl-some '(lambda (y_unique) (equal _y y_unique y_fuzz)) unique_y_list)) (setq unique_y_list (append unique_y_list (list _y)))))
(setq center_list (mapcar '(lambda (_y) (vl-remove-if-not '(lambda (center) (equal (cadr center) _y y_fuzz)) center_list)) unique_y_list)
center_list (mapcar '(lambda (y_sublist) (if (zerop (rem (vl-position y_sublist center_list) 2))
(vl-sort y_sublist '(lambda (center_1 center_2) (< (car center_1) (car center_2))))
(vl-sort y_sublist '(lambda (center_1 center_2) (> (car center_1) (car center_2))))
)
)
center_list
)
3dpoly_vertices_list (apply 'append (apply 'append center_list))
)
(vla-add3dpoly (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 1 (length 3dpoly_vertices_list)))
3dpoly_vertices_list
)
)
)
)
(princ)
)
Works almost perfect! really appreciate it!
I have encounter an issue:
I have planes that are arranged in a 3d shape and the dots are placed flat on each plane. When I try to flatten the 3d planes into 2d projection the LISP does not select the circles.
Also, can I ask you to help me to add a restriction of the line between the center of the circles to be not more than 250mm?
Appreciate your help!
Can't you see that your codes are written in manner that your lines go to much right, so it's very difficult to follow what you've written... If you don't mind, I'll post your code prittyfied manually by me, so that everyone is able to see it easy, at least little better than your original version...
(defun c:meander ( / circle_sset center_list y_coordinate_list unique_y_list 3dpoly_vertices_list ) (or (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-get-acad-object nil))) (vl-load-com)) (if (setq circle_sset (ssget '((0 . "circle")))) (progn (setq center_list (mapcar '(lambda ( circle ) (vlax-get circle 'center)) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex circle_sset))))) y_coordinate_list (vl-sort (mapcar 'cadr center_list) '<) y_fuzz 1 ) (foreach _y y_coordinate_list (if (not (vl-some '(lambda ( y_unique ) (equal _y y_unique y_fuzz)) unique_y_list)) (setq unique_y_list (append unique_y_list (list _y)))) ) (setq center_list (mapcar '(lambda ( _y ) (vl-remove-if-not '(lambda ( center ) (equal (cadr center) _y y_fuzz)) center_list)) unique_y_list) center_list (mapcar '(lambda ( y_sublist ) (if (zerop (rem (vl-position y_sublist center_list) 2)) (vl-sort y_sublist '(lambda ( center_1 center_2 ) (< (car center_1) (car center_2)))) (vl-sort y_sublist '(lambda ( center_1 center_2 ) (> (car center_1) (car center_2)))) ) ) center_list ) 3dpoly_vertices_list (apply 'append (apply 'append center_list)) ) (vla-add3dpoly (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))) (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 1 (length 3dpoly_vertices_list))) 3dpoly_vertices_list ) ) ) ) (princ) )
Can't find what you're looking for? Ask the community or share your knowledge.