The drawing units are in meters.
Objects in the array are spaced 30.49m (100 ft) apart. At every 30.49m, stationing labels will be generated, starting from 0+00, 1+00, 2+00, increasing in increments of 100.
The polyline/array represents the centerline of a road.
I have created a LISP routine that works fine, but currently, it places TEXT instead of MText.
(defun c:STATIONING ( / cl obj1 obj2 pt1 pt2 dirx diry i station count spacing len param pt)
(setq spacing 30.49) ;; Fixed spacing in meters (each step = 100 station units)
;; Select the centerline polyline
(setq cl (car (entsel "\nSelect centerline polyline: ")))
(if (not (and cl (= (cdr (assoc 0 (entget cl))) "LWPOLYLINE")))
(progn
(princ "\nInvalid selection. Please select a polyline.")
(exit)
)
)
;; Select first object in the array
(setq obj1 (car (entsel "\nSelect first object in the array: ")))
;; Select second object to determine array direction
(setq obj2 (car (entsel "\nSelect second object in the array: ")))
(if (and obj1 obj2)
(progn
;; Get object positions
(setq pt1 (cdr (assoc 10 (entget obj1))))
(setq pt2 (cdr (assoc 10 (entget obj2))))
;; Compute array direction (unit vector)
(setq dirx (/ (- (car pt2) (car pt1)) spacing))
(setq diry (/ (- (cadr pt2) (cadr pt1)) spacing))
;; Get centerline length
(setq len (vlax-curve-getDistAtParam cl (vlax-curve-getEndParam cl)))
;; Calculate number of objects based on centerline length
(setq count (fix (/ len spacing)))
;; Start placing stationing labels
(setq i 0
station 0
param 0)
(while (< i count)
(setq pt (vlax-curve-getPointAtDist cl (* i spacing))) ;; Get exact point on centerline
(if pt
(command "_TEXT" pt 1 0 (strcat (itoa station) "+00")) ;; Place station label
)
(setq i (1+ i)
station (1+ station)) ;; Increment station (100 units per step)
)
(princ "\nStationing added successfully!")
)
(princ "\nError: Could not determine array direction.")
)
(princ)
)