Message 1 of 3
Shortest path
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello again everyone.
I'm trying to create a function that gets the shortest path between two points.
The objective is to select a set of points, determine the beginning and end, store all points in a variable and draw a polyline along the shortest path, obeying the rule that the distance between one point and another does not exceed 50 units. If you happen to overtake, just mark the points you have exceeded.
Leaving an example .dwg for ease of understanding.
I thank you for your availability.
;;reference
;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/connect-selected-blocks-with-the-smallest-polyline-length/td-p/8419663
(defun closer (a b c)
(< (distance a b)(distance a c))
)
(defun c:shortestway ( )
;;start point
(setq start_point '(254.1110 1.6016 0.0000))
;;End point
(setq end_point '(391.3819 138.1919 0.0000))
;;shortest distance
(setq shortest_distance (distance start_point end_point))
;;maximum span length
(setq maximum_length 50.0)
;;select
(setq select (ssget))
;;build a list with the points
(repeat (setq i (sslength select))
(setq lst (cons (cdr (assoc 10 (entget (ssname select (setq i (1- i)))))) lst))
)
(setq rte (list start_point))
;;loop
(while lst
(setq start_point (car (vl-sort lst '(lambda (a b) (closer pni a b)))))
(setq lst (vl-remove start_point lst))
(setq rte (cons start_point rte))
)
;;draw the pline
(vl-cmdf "_.pline")
(mapcar 'vl-cmdf (reverse rte))
(vl-cmdf "")
)
;(c:shortestway)