;;;Elise Moss ;;;www.mossdesigns.com ;;;July 2007 ;;;This routine has the user select a line and then places text below the line at the midpoint with the length value of the line. Uses the current text style and layer for the text (defun c:llen (/) (setq txt-ins-pt nil) ; this just initiates the point list so if you use this routine multiple times it doesn't have an error ;first the user has to select a line (setq li-ent (car (entsel "\nSelect a line to label: "))) ; check to see if a line or polyline was selected (setq li-data (entget li-ent)) (setq li-type (cdr (assoc 0 li-data))) ; have a check to make sure a polyline or line was selected (while (and (/= li-type "LWPOLYLINE") (/= li-type "LINE")) ;first the user has to select a line (setq li-ent (car (entsel "\nSelect a line to label: "))) ; check to see if a line or polyline was selected (setq li-data (entget li-ent)) (setq li-type (cdr (assoc 0 li-data))) ) ;end while ; now we know we have a polyline or line ; get the length of the object (vl-load-com) (setq curve (vlax-ename->vla-object li-ent)) (setq ent-length (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve) ) ) ; convert the length to a string value with no decimal places (setq ent-length-text (rtos ent-length 2 0)) ;;now we need to determine the insertion point for the text ;;to do this we need the midpoint for the line and the text-height ;;if this is a polyline there might be more than one vertex ;;first we get the start and point for the polyline (setq st-point (vlax-curve-getStartPoint li-ent)) (setq en-point (vlax-curve-getEndPoint li-ent)) ;;ok but which is really the start point (setq x-st-point (car st-point)) (setq x-en-point (car en-point)) (setq x-list (list x-st-point x-en-point)) ; now locate the smallest point (setq x-start (apply 'min x-list)) ;;next we get the x-value we are going to move which is half the length (setq mid-x (/ ent-length 2)) ;;add the distance to shift to the mid-x point (setq new-x (+ x-start mid-x)) ;; now the y is a little trickier ;;first we need to determine the current text style (setq cur-textstyle (getvar "TEXTSTYLE")) ; then we see what the text height should be (setq text-style-data (entget (tblobjname "style" cur-textstyle))) (setq cur-textheight (cdr (assoc 40 text-style-data))) ; if it is nil, we need to prompt for the text height (if (= cur-textheight nil) (setq cur-textheight (getint "\N Enter text height to be used: ")) ) ; end if ;; time to set new y point ; get the y value for the start point (setq y-st-point (cadr st-point)) ;;add the distance to shift to the mid-y point (setq new-y (- y-st-point cur-textheight)) ;;build the new ins-point (setq txt-ins-pt (list new-x new-y)) ; time to place the text (command "text" "j" "c" txt-ins-pt "0" ent-length-text "") ) ;; end routine