;;;C:LINELEGEND ;;;Function to label a selection set of lines with user supplied text ;;;Autoscales text to plot at current value of DIMTXT ;;;Text may be placed above, below or centered on lines. ;;;Works on a selection set of lines only, not polylines. ;;;If the text is centered on the lines, the lines are broken around the text. ;;;Calls TRIM to break the lines, so if the text is longer than the line, ;;;the line will not be broken, but text will be written over the line segment. ;;;Uses current value of TEXTSTYLE for text style. ;;;Option to use a predefined layer or current layer - see below ;;; ;;;Copyright © 2001 by Herman Mayfarth ;;;Provided as is and with all faults. No warranty of any kind. ;;;Permission granted to freely use and redistribute without fee, ;;;provided copyright notice and disclaimer of warranty remain intact. ;;;Author: h_mayfarth@tktn.com http://www.tktn.com ;;; ;;;Created:5 July 1999 ;;;Version:1.1 9 Feb. 00 ;;;Added option for Above/Below lines ;;;Changed text style from DIMTXSTY to TEXTSTYLE ;;;Version 1.2 2 Aug 01 ;;;Added option to center text on lines & break lines around text ;;;No error handler. ;;;Written for and tested with AutoCAD R14.01 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; GLOBAL variable for line labels ;; change to suit your needs ;; comment out the following ONE line to place text on the current layer (setq lbl_layer "LINE_LEGEND") (if (not lbl_layer) (setq lbl_layer (getvar "CLAYER"))) (defun C:LINELEGEND( / ss1 ss2 i n pt1 pt2 midpt langle sstyle sf txtht txtsty ename gap legend inspt elist vpht curvpt txtloc vert) ;;start an undo group (command "_.UNDO" "BEGIN") ;; handle nonsense case of zero dimscale in tiled space (if(and(= 0 (getvar "DIMSCALE"))(= 1 (getvar "TILEMODE"))) (progn((alert " Zero Dimension Scale\n Set Tilemode = 0 or Use a Non-Zero Dimension Scale")(exit)))) ;; calculate text scale factor (setq curvpt (getvar "CVPORT")) (cond ((= 1 (getvar "TILEMODE")) (setq sf (getvar "DIMSCALE")));tiled space ((= 1 curvpt) (setq sf 1.0));in paper space ;; in a viewport (T (setq ss2 (ssget "X" (list '(0 . "VIEWPORT") (cons 69 curvpt)));select vport vpht (cdr(assoc 41 (entget(ssname ss2 0))));set vp height sf (/ (getvar "VIEWSIZE") vpht));calc scale factor );end default );end cond ;; calculate text height (setq txtht (* (getvar "DIMTXT") sf)) ;; get current text style (setq txtsty (getvar "TEXTSTYLE")) (setq sstyle (tblsearch "style" txtsty)) (setq gap (getvar "DIMGAP")) ;;prompt user for text location (initget "Above Below Center") (setq txtloc (getkword "\nText Location: Above Below