But there is another, simpler way to get the intersection, which makes the part of your code that gets the lists of points unnecessary: 'vla-intersectWith'
Simply replace the line of code that starts with '(setq kl (inters ...))' with...
(setq kl (safearray-value (variant-value (vla-intersectWith (vlax-ename->vla-object poly) (vlax-ename->vla-object line) 0))))
The answer is simple: the first segment of the polyline does not intersect the line.
If, at first glance, you can see that the line intersects the polyline, it means that it does so in another segment, but not in the first one.
So that no one says that I throw stones and hide my hand, here is my proposal for improvement.
(defun c:myDimAlign (/ x e p s d o pS os xD asr dt pr ar osmant)
;; A D * I N F I N I T V M A D * I N F I N I T V M A D * I N F I N I T V M
;; A D * I N F I N I T V M A D * I N F I N I T V M A D * I N F I N I T V M
;; ;;;
;; GGGG LL A VV VV CCCC VV VV SSSS ;;;
;; GG GG LL AA AA VV VV CC CC VV VV SS SS ;;;
;; GG LL AA AA VV VV CC VV VV SS ;;;
;; GG GGGG LL AA AA VV VV CC VV VV SSSS ;;;
;; GG GG LL AA AAA AA VV VV CC VV VV SS ;;;
;; GG GG LL LL AA AA V V CC CC V V SS SS ;;;
;; GGG LLLLLLLL AA AA VV CCCC VV SSSS ;;;
;; ;;;
;; A D * I N F I N I T V M A D * I N F I N I T V M A D * I N F I N I T V M
;; A D * I N F I N I T V M A D * I N F I N I T V M A D * I N F I N I T V M
(defun os (/ d p i)
(while (and
(setq f (cdr (assoc 10 (setq x (cdr (member (setq p (assoc 10 x)) x))))))
(/= (max (distance (cdr p) pS) (distance f pS) (setq d (distance (setq i (cdr p)) f))) d)
)
)
i
)
(defun xD (c1 c2 / ed pt r of)
(if (not dt)
(setq dt (distance o (cadr s)) ar (asr (os) pS o))
)
(polar c2 (ar (angle c1 c2) (/ pi 2)) dt)
)
(defun asr (p1 p2 p3 / a b)
(if (> (abs (- (setq a (angle p1 p2)) (setq b (angle p2 p3)))) PI)
(if (< a b)
(if (> (+ a PI PI) b) - +)
(if (> (- a PI PI) b) - +)
)
(if (> a b) - +)
)
)
(setq osmant (getvar 'OSMODE))
(setvar 'OSMODE 0)
(if (and (setq e (car (setq s (entsel "\nSelect any LWpolyline..."))))
(= (cdr (assoc 0 (setq x (entget e)))) "LWPOLYLINE")
(setq o (getpoint (setq pS (cadr s)) "\nSide to act on..."))
)
(foreach g (if (= (rem (cdr (assoc 70 x)) 2) 0) x (setq x (append x (list (assoc 10 x)))))
(if (= (car g) 10)
(if p
(command "_DIMALIGNED" p (cdr g) (xD p (setq p (cdr g))))
(setq p (cdr g))
)
)
)
)
(if osmant (setvar 'OSMODE osmant))
(princ)
)