you could try this, it puts the text on the annotation layer, and it gives you a couple more options. Option 3 sounds like what you want. It is supposed to drop the text at the midpoint of the object selected, rotated parallel (or tangent) to the object at that point.
Code:
(defun MakeLayer (lyrname acDoc / lyrobj)
(vl-load-com)
(if
(not
(vl-catch-all-error-p
(setq lyrobj
(vl-catch-all-apply
'vla-add
(list (vla-get-layers acDoc) lyrname)
) ;_ end of vl-catch-all-apply
) ;_ end of setq
) ;_ end of vl-catch-all-error-p
) ;_ end of not
lyrobj
) ;_ end of if
) ;_ end of defun
(defun c:lengthtext (/ lengthmode object
objchk listobj vlobj
MidPoint Param startpline
endpline vlobjlen1 angle1
Ang TH vlobjang
textobj1 textobj2 vlobjang1
vlobjang2 lengthscale lyrobj
)
(if (not (tblsearch "Layer" "Annotation"))
(if (setq lyrobj (MakeLayer "Annotation" acadDocument))
(progn
(vla-put-color lyrobj acgreen)
(vla-put-plottable lyrobj :vlax-true)
(vlax-release-object lyrobj)
) ;_ end of progn
(setq errmsg "\nLayer Make failed for Annotation layer")
) ;_ end of if
) ;_ end of if
(setq lengthmode
(getint
"\nSpecify Mode (1 = One Decimal, 2 = Two Decimals, 3 = Two Decimals with Bearing"
) ;_ end of getint
lengthscale (atoi (vl-string-left-trim
":"
(vl-string-left-trim
"1234567890"
(getvar "cannoscale")
) ;_ end of vl-string-left-trim
) ;_ end of vl-string-left-trim
) ;_ end of atoi
) ;_ end of setq
(if (= lengthmode 3)
(setq
object
(ssget
(list
(cons 0
"ARC,LINE"
) ;_ end of cons
) ;_ end of list
) ;_ end of ssget
) ;_ end of setq
(setq
object
(ssget
(list
(cons 0
"POLYLINE,*CONTOUR,ARC,LINE,LWPOLYLINE,2DPOLYLINE"
) ;_ end of cons
) ;_ end of list
) ;_ end of ssget
) ;_ end of setq
) ;_ end of if
(while (setq listobj (ssname object 0))
(setq vlobj (vlax-ename->vla-object listobj))
(if (/= (cdr (assoc 0 (entget listobj))) "ARC")
(setq vlobjlen1 (vla-get-length vlobj)
objchk 1
) ;_ end of setq
(setq vlobjlen1 (vla-get-arclength vlobj)
objchk 2
) ;_ end of setq
) ;_ end of if
(setq MidPoint (vlax-curve-getpointatdist
vlObj
(/ vlobjlen1 2)
) ;_ end of vlax-curve-getpointatdist
Param (vlax-curve-getParamAtPoint VlObj MidPoint)
startpline (vlax-curve-getStartParam VlObj)
endpline (vlax-curve-getEndParam VlObj)
angle1 (vlax-curve-getFirstDeriv
VlObj
(/ (- endpline startpline) 2)
) ;_ end of vlax-curve-getFirstDeriv
TH (* 0.08 lengthscale)
) ;_ end of setq
(if (= objchk 1)
(progn
(if (equal (car angle1) 0.0 0.01)
(setq Ang (/ pi 2))
(setq Ang (atan (/ (cadr angle1) (car angle1))))
) ;_ end of if
(setq
vlobjang (angtos Ang 4 3)
vlobjang1 (vl-string-left-trim "NS 0123456789" vlobjang)
vlobjang2 (vl-string-right-trim
"EW \"0123456789'"
vlobjang
) ;_ end of vl-string-right-trim
vlobjang2 (vl-string-right-trim "d" vlobjang2)
vlobjang (strcat vlobjang2 "%%" vlobjang1)
) ;_ end of setq
) ;_ end of progn
(setq
Ang (- (/ (+ (vla-get-endangle vlobj)
(vla-get-startangle vlobj)
) ;_ end of +
2
) ;_ end of /
(/ pi 2)
) ;_ end of -
vlobjang (angtos Ang 4 3)
vlobjang1 (vl-string-left-trim "NS 0123456789" vlobjang)
vlobjang2 (vl-string-right-trim "EW \"0123456789'" vlobjang)
vlobjang2 (vl-string-right-trim "d" vlobjang2)
vlobjang (strcat vlobjang2 "%%" vlobjang1)
) ;_ end of setq
) ;_ end of if
(cond
((= lengthmode 1)
(if (wcmatch (rtos vlobjlen1 2 1) "*`.*")
(setq vlobjlen (strcat (rtos vlobjlen1 2 1) "'"))
(setq vlobjlen (strcat (rtos vlobjlen1 2 1) ".0'"))
) ;_ end of if
(setq textObj1 (vla-addtext
acadModelSpace
vlobjlen
(vlax-3d-point Midpoint)
TH
) ;end vla-addtext
) ;end setq
)
((= lengthmode 2)
(cond
((wcmatch (rtos vlobjlen1 2 2) "*`.##")
(setq vlobjlen (strcat (rtos vlobjlen1 2 2) "'")
) ;_ end of setq
)
((wcmatch (rtos vlobjlen1 2 2) "*`.#")
(setq vlobjlen (strcat (rtos vlobjlen1 2 2) "0'")
) ;_ end of setq
)
((wcmatch (rtos vlobjlen1 2 2) "*")
(setq vlobjlen (strcat (rtos vlobjlen1 2 2) ".00'")
) ;_ end of setq
)
) ;_ end of cond
(setq
textObj1 (vla-addtext
acadModelSpace
vlobjlen
(vlax-3d-point Midpoint)
TH
) ;end vla-addtext
) ;end setq
)
((= lengthmode 3)
(cond
((wcmatch (rtos vlobjlen1 2 2) "*`.##")
(setq vlobjlen (strcat (rtos vlobjlen1 2 2) "'")
) ;_ end of setq
)
((wcmatch (rtos vlobjlen1 2 2) "*`.#")
(setq vlobjlen (strcat (rtos vlobjlen1 2 2) "0'")
) ;_ end of setq
)
((wcmatch (rtos vlobjlen1 2 2) "*")
(setq vlobjlen (strcat (rtos vlobjlen1 2 2) ".00'")
) ;_ end of setq
)
) ;_ end of cond
(setq
textObj1 (vla-addtext
acadModelSpace
vlobjlen
(vlax-3d-point Midpoint)
TH
) ;end vla-addtext
textobj2 (vla-addtext
acadModelSpace
vlobjang
(vlax-3d-point Midpoint)
TH
) ;_ end of vla-addtext
) ;end setq
)
) ;_ end of cond
(vla-put-color textobj1 256) ;change color
(vla-put-alignment textobj1 13) ;change justification
(vla-put-textalignmentpoint
textobj1
(vlax-3d-point Midpoint)
) ;_ end of vla-put-textalignmentpoint
;change insetion point
(vla-put-rotation textobj1 Ang)
;change rotation
(vla-put-layer textobj1 "Annotation")
(if (/= textObj2 nil)
(progn
(vla-put-color textobj2 256)
(vla-put-alignment textobj2 13)
(vla-put-textalignmentpoint
textobj2
(vlax-3d-point
(list
(+ (car Midpoint) (* (sin ang) (* 0.16 lengthscale)))
(- (cadr Midpoint) (* (cos ang) (* 0.16 lengthscale)))
(caddr Midpoint)
) ;_ end of list
) ;_ end of vlax-3d-point
) ;_ end of vla-put-textalignmentpoint
(vla-put-rotation textobj2 Ang)
(vla-put-layer textobj2 "Annotation")
) ;_ end of progn
) ;_ end of if
(ssdel listobj object)
) ;end while
) ;end defun