;;; Draw "average" spline/pline between two splines/plines.
;;; Created by Stefan BMR
;;; Saved from here: http://www.cadtutor.net/forum/showthread.php?97472-Draw-quot-average-quot-spline-pline-between-two-splines-plines

(defun c:cpl ( / a1 a2 d1 d2 e1 e2 k l n p1 p2 x1 x2)
(defun start_p (e p)
(< (vlax-curve-getdistatpoint
e
(vlax-curve-getclosestpointto e p)
)
(/ (vlax-curve-getdistatparam
e
(vlax-curve-getendparam e)
)
2.0
)
)
)
(defun m2p (a b) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) a b))
(if
(and
(setq e1 (entsel "\nSelect the first object: "))
(setq e2 (entsel "\nSelect the second object: "))
(not (eq (car e1) (car e2)))
(or
(setq n (getint "\nNumber of divisions : "))
(setq n 10)
)
)
(progn
(setq p1 (trans (cadr e1) 1 0)
e1 (car e1)
p2 (trans (cadr e2) 1 0)
e2 (car e2)
a1 (vlax-curve-getdistatparam e1 (vlax-curve-getendparam e1))
x1 (/ a1 n)
a2 (vlax-curve-getdistatparam e2 (vlax-curve-getendparam e2))
x2 (/ a2 n)
)
(if (start_p e1 p1) (setq d1 0.0) (setq d1 a1 x1 (- x1)))
(if (start_p e2 p2) (setq d2 0.0) (setq d2 a2 x2 (- x2)))
(repeat (1+ n)
(setq l (cons
(m2p
(vlax-curve-getpointatdist e1 d1)
(vlax-curve-getpointatdist e2 d2)
)
l
)
d1 (min a1 (max 0.0 (+ d1 x1)))
d2 (min a2 (max 0.0 (+ d2 x2)))
)
)
(initget "Polyline Spline")
(setq k (getkword "\nSpecify object type [Polyline/Spline]: "))
(if
(eq k "Spline")
(entmakex
(append
(list
'(0 . "SPLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbSpline")
'(70 . 40)
'(71 . 3)
(cons 74 (length l))
'(44 . 1.0e-005)
)
(mapcar '(lambda (x) (cons 11 x)) l)
)
)
(entmakex
(append
(list
'(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(70 . 0)
(cons 90 (length l))
)
(mapcar '(lambda (x) (cons 10 x)) l)
)
)
)
)
)
(princ)
)
(c:cpl)

Advertisements