Anushka Posted Thursday at 07:37 PM Share Posted Thursday at 07:37 PM I have a function that draws a polyline along the shortest path through a series of points. I've managed to modify it to break the polyline when it reaches the maximum bobbin length. However, I need help refining the function so that when the maximum length is reached, it segments the polyline at the nearest block point within the point list (plist). Additionally, if the gap between points in plist is greater than the bobbin length, the function should add a new segment without aligning exactly with a plist point. How can I perform this check and adjustment efficiently? ; ;; Routine to draw a polyline along the shortest route from ; ;; any starting point through selected circles or inserts in Modelspace ; ;; John Uhden (07-22-18) ; ;; Rev. (11-25-18) to include inserts and selection. (defun c:OTIMIZEROTA ( / ss i p plist route @closer compbobina comprimento-atual pnt-segmento) ;; Função para encontrar o ponto mais próximo na lista (defun @closer (a b c) (< (distance a b) (distance a c))) ;; Seleção dos blocos e entrada do ponto inicial (and (setq ss (ssget '((0 . "INSERT")))) (setq p (getpoint "\nSelect or specify the starting point - use osnap CEN or INS: ")) (setq compbobina (getreal "\nCoil length: ")) (foreach i (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq ent i) (setq obj (vlax-ename->vla-object ent)) (setq pnt (vlax-get obj 'insertionpoint)) (setq rot (vlax-get obj 'Rotation)) (setq _pnt (polar pnt (+ rot (* 0.5 pi)) 3.57403916)) (setq plist (cons _pnt plist)) ) (setq comprimento-atual 0) (while plist (setq route (list p)) (setq comprimento-atual 0) (while (and plist (< comprimento-atual compbobina)) (setq pnt-segmento (car (vl-sort plist '(lambda (a b) (@closer p a b))))) (setq nova-distancia (distance p pnt-segmento)) (if (<= (+ comprimento-atual nova-distancia) compbobina) (progn (setq route (cons pnt-segmento route)) (setq comprimento-atual (+ comprimento-atual nova-distancia)) (setq p pnt-segmento plist (vl-remove pnt-segmento plist))) (progn (setq p (polar p (angle p pnt-segmento) (- compbobina comprimento-atual))) (setq route (cons p route)) (setq comprimento-atual compbobina) ) ) ) (setvar "osmode" 0) (setvar "cmdecho" 0) (vl-cmdf "_.pline") (mapcar 'vl-cmdf (reverse route)) (vl-cmdf "") (vl-cmdf "_.point" p) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted Thursday at 09:59 PM Share Posted Thursday at 09:59 PM Just one suggestion (setq oldsnap (getvar 'osmode)) (setvar 'osmode 68) (setq p (getpoint "\nSelect or specify the starting point: ")) .......... code (setvar 'osmode oldsnap) (princ) ) A dwg may help with before and after examples. Quote Link to comment Share on other sites More sharing options...
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.