Hi,
I have a somewhat similar procedure, but it works with two polylines.
Two solutions are drawn up in the end, you just have to keep one of your choice!
I'm attaching your example drawing modified to work with my procedure.
Does this sound interesting to you?
(vl-load-com)
(defun add_vtx (obj add_pt ent_name / bulg)
(vla-addVertex
obj
(1+ (fix add_pt))
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vlax-vbdouble (cons 0 1))
(list
(car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
(cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
)
)
)
)
(setq bulg (vla-GetBulge obj (fix add_pt)))
(vla-SetBulge obj
(fix add_pt)
(/
(sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
(cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
)
)
(vla-SetBulge obj
(1+ (fix add_pt))
(/
(sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
(cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
)
)
(vla-update obj)
)
(defun c:vertex_median ( / fst_ob snd_obj vrt_pt pt lst_pt fst_dxf snd_dxf lst1 lst2 lstx ptx)
(princ "\nSelect first polyline: ")
(while (not (setq fst_obj (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
(princ "\nSelect second polyline: ")
(while (not (setq snd_obj (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
(setq
fst_obj (ssname fst_obj 0)
snd_obj (ssname snd_obj 0)
vrt_pt (vlax-variant-value (vla-IntersectWith (vlax-ename->vla-object fst_obj) (vlax-ename->vla-object snd_obj) 0))
)
(if (>= (vlax-safearray-get-u-bound vrt_pt 1) 0)
(progn
(setq pt (vlax-safearray->list vrt_pt))
(if pt
(if (> (length pt) 3)
(repeat (/ (length pt) 3)
(setq lst_pt (cons (list (car pt) (cadr pt) (caddr pt)) lst_pt) pt (cdddr pt))
)
(setq lst_pt (cons pt lst_pt))
)
)
)
)
(setq
fst_dxf (entget fst_obj)
snd_dxf (entget snd_obj)
lst1 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) fst_dxf))
lst2 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) snd_dxf))
lstx nil
)
(if (and lst_pt (listp lst_pt))
(progn
(setq obj (vlax-ename->vla-object fst_obj))
(foreach el lst_pt
(if (not (member T (mapcar '(lambda (x) (equal (list (car el) (cadr el)) x 1E-8)) lst1)))
(add_vtx obj (vlax-curve-getparamatpoint obj (vlax-curve-getClosestPointTo obj el)) fst_obj)
)
)
(setq obj (vlax-ename->vla-object snd_obj))
(foreach el lst_pt
(if (not (member T (mapcar '(lambda (x) (equal (list (car el) (cadr el)) x 1E-8)) lst2)))
(add_vtx obj (vlax-curve-getparamatpoint obj (vlax-curve-getClosestPointTo obj el)) snd_obj)
)
)
)
)
(setq
fst_dxf (entget fst_obj)
snd_dxf (entget snd_obj)
lst1 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) fst_dxf))
lst2 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) snd_dxf))
lstx nil
)
(foreach n lst1
(setq
pt (nth (vl-position (apply 'min (setq lst_d (mapcar '(lambda (x) (distance n x)) lst2))) lst_d) lst2)
ptx (list (* 0.5 (+ (car n) (car pt))) (* 0.5 (+ (cadr n) (cadr pt))))
lstx (cons ptx lstx)
)
)
(entmake
(append
(list
(cons 0 "LWPOLYLINE")
(cons 100 "AcDbEntity")
(assoc 67 fst_dxf)
(assoc 410 fst_dxf)
(assoc 8 fst_dxf)
(if (assoc 62 fst_dxf) (assoc 62 fst_dxf) (cons 62 256))
(if (assoc 6 fst_dxf) (assoc 6 fst_dxf) (cons 6 "BYLAYER"))
(if (assoc 370 fst_dxf) (assoc 370 fst_dxf) (cons 370 -1))
(cons 100 "AcDbPolyline")
(cons 90 (length lstx))
(assoc 70 fst_dxf)
(if (assoc 38 fst_dxf) (assoc 38 fst_dxf) (cons 38 0.0))
(if (assoc 39 fst_dxf) (assoc 39 fst_dxf) (cons 39 0.0))
)
(apply 'append
(mapcar
'(lambda (x10)
(list
(cons 10 x10)
'(40 . 0.0)
'(41 . 0.0)
'(42 . 0.0)
'(91 . 0)
)
)
lstx
)
)
(list (assoc 210 fst_dxf))
)
)
(setq lstx nil)
(foreach n lst2
(setq
pt (nth (vl-position (apply 'min (setq lst_d (mapcar '(lambda (x) (distance n x)) lst1))) lst_d) lst1)
ptx (list (* 0.5 (+ (car n) (car pt))) (* 0.5 (+ (cadr n) (cadr pt))))
lstx (cons ptx lstx)
)
)
(entmake
(append
(list
(cons 0 "LWPOLYLINE")
(cons 100 "AcDbEntity")
(assoc 67 snd_dxf)
(assoc 410 snd_dxf)
(assoc 8 snd_dxf)
(if (assoc 62 snd_dxf) (assoc 62 snd_dxf) (cons 62 256))
(if (assoc 6 snd_dxf) (assoc 6 snd_dxf) (cons 6 "BYLAYER"))
(if (assoc 370 snd_dxf) (assoc 370 snd_dxf) (cons 370 -1))
(cons 100 "AcDbPolyline")
(cons 90 (length lstx))
(assoc 70 snd_dxf)
(if (assoc 38 snd_dxf) (assoc 38 snd_dxf) (cons 38 0.0))
(if (assoc 39 snd_dxf) (assoc 39 snd_dxf) (cons 39 0.0))
)
(apply 'append
(mapcar
'(lambda (x10)
(list
(cons 10 x10)
'(40 . 0.0)
'(41 . 0.0)
'(42 . 0.0)
'(91 . 0)
)
)
lstx
)
)
(list (assoc 210 snd_dxf))
)
)
(sssetfirst nil (ssadd snd_obj (ssadd fst_obj (ssadd))))
(prin1)
)
Test example.dwg