@Anonymous hi,
Check this one. it call ARPTH (Array Path)
this program is base on Lee's Mac (LM:randrange) function to get a random value so thank you very much Lee Mac
it works in a loop letting you pick a line path (actually it's a curve which lets you also select a polylines and splines) each one in a row.
the next code line defined the fix distances. you can changes these numbers as you like to meet your requirements.
(setq FIXVAL '(5.35 6.68 4.59 7.51 8.23 9.15 5.35 6.75 7.45))
also there is a constant defines the circle radius you can set it with your radius
(setq RADIUS 2)
another constant refers to the randomize value. there must be a limit for trying to get a random value otherwise the program might enter an infinite loop 😀 if 96 is a low value, you can increase (or decrease) it to speed the program.
(setq RANDTRY 96)
the program make sure there will not be an overlapping circles if you did not mind this i can remove this check.
and last:
the circles in each line path (curve) is collected and put in a group, giving the feel of array path (it's totally static you can not edit it, only select to move\copy\rotate or delete)
enjoy
Moshe
;; Rand - Lee Mac
;; PRNG implementing a linear congruential generator with
;; parameters derived from the book 'Numerical Recipes'
(defun LM:rand ( / a c m )
(setq m 4294967296.0
a 1664525.0
c 1013904223.0
$xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
)
(/ $xn m)
)
;; Random in Range - Lee Mac
;; Returns a pseudo-random integral number in a given range (inclusive)
(defun LM:randrange ( a b )
(+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b))))))
)
(defun c:arpth (/ wcs->ucs randomize ; local functions
RADIUS FIXVAL ss0 ss1 pick ename p0 p1 d0 d1 d2 seg len rnd dirMode bool)
(defun wcs->ucs (pt)
(trans pt 0 1)
)
(defun randomize (/ n r)
(setq n 0)
(while (and
(< n RANDTRY) ; make sure not enter infinite loop
(< (setq r (nth (LM:randrange 0 (length FIXVAL)) FIXVAL)) (* RADIUS 2))
)
(setq n (1+ n))
)
(if (= n RANDTRY)
(alert "radomize fail to generate a reasonable number.")
r)
); radomize
; here start c:arpth
(setvar "cmdecho" 0)
(command "._undo" "_begin")
; constant declaration
(setq RANDTRY 96) ; max radomize tries
(setq RADIUS 2) ; fix circle radius
; fix dist values
(setq FIXVAL '(5.35 6.68 4.59 7.51 8.23 9.15 5.35 6.75 7.45))
(while (setq ss0 (ssget ":s:e+." '((0 . "*line")))) ; line,polyline,lwpolyline,spline can be picked here
(setq pick (ssnamex ss0))
(setq ename (cadar pick))
(setq p0 (cadr (last (car pick))))
(setq d0 0.0)
(setq d1 (vlax-curve-getDistAtParam ename (vlax-curve-getParamAtPoint ename (vlax-curve-getClosestPointTo ename p0))))
(setq d2 (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
(if (setq dirMode (< d1 (- d2 d1)))
(setq bool '< seg 0.0 upto d2)
(setq bool '> seg d2 upto 0.0)
)
(setq rnd t len d2)
(setq ss1 (ssadd)) ; for group
(while (and rnd (eval (list bool seg upto)))
(setq p1 (wcs->ucs (vlax-curve-getPointAtDist ename seg)))
(command "._circle" p1 RADIUS)
(ssadd (entlast) ss1)
(if (setq rnd (randomize))
(if dirMode
(setq seg (+ seg rnd))
(setq seg (- len (setq d0 (+ d0 rnd))))
); if
); if
); while
(command "._group" "" "*" "" "_si" ss1)
(setq ss1 nil)
); while
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
); c:arpth