My suggestion in Message 5 will give you the middle vertex [or one of the two] in terms of the quantity of vertices, which admittedly in some Polylines could be far from the middle of the overall length -- that's what Message 7 is designed to give you.
Just as a suggestion, a simpler way to do this much:
....
(setq l_obj (vlax-ename->vla-object (setq ent (ssname ss (setq cnt (1- cnt)))))
len (vlax-get-property l_obj 'length)
m_pt (vlax-curve-getpointatdist ent (/ len 2.0))
f_p (fix (vlax-curve-getparamatpoint ent m_pt))
d1 (vlax-curve-getpointatparam ent f_p)
d2 (vlax-curve-getpointatparam ent (1+ f_p))
)
(if (> (distance d1 m_pt) (distance m_pt d2)) (setq i_pt d2) (setq i_pt d1))
....
would be like this, getting the length by a way that doesn't require conversion to a VLA object [used for no other purpose], and using a common round-up-or-down approach [add 1/2 and (fix) the result downward], thereby eliminating the need for the l_obj, d1 and d2 variables and that (if) test:
....
(setq
ent (ssname ss (setq cnt (1- cnt)))
len (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))
m_pt (vlax-curve-getpointatdist ent (/ len 2)); 2 can be an integer, since len will be real
i_pt (vlax-curve-getPointAtParam ent (fix (+ (vlax-curve-getparamatpoint ent m_pt) 0.5)))
)
....
You could even eliminate the len and m_pt variables, too [they're used only once each, so you can instead just put their definitions in those places directly]:
....
(setq
ent (ssname ss (setq cnt (1- cnt)))
i_pt (vlax-curve-getPointAtParam ent (fix (+ (vlax-curve-getparamatpoint ent (vlax-curve-getpointatdist ent (/ (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) 2))) 0.5)))
); setq
....
Or, to break that long line down to see the relationships:
....
(setq
ent
(ssname ss (setq cnt (1- cnt)))
i_pt
(vlax-curve-getPointAtParam ent
(fix
(+
(vlax-curve-getparamatpoint ent
(vlax-curve-getpointatdist ent ; what was m_pt
(/ (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) 2); what was len
); ...PointAtDist
); ...ParamAtPoint
0.5
); +
); fix
); ...PointAtParam
); setq
....
Kent Cooper, AIA