View Full Version : inserting text
rstiles
2005-01-24, 09:03 PM
I have a site DWG that I am working on and I need to label each section of pipe. does someone have a lisp that places text at the rotation and at a set distance from a selected line? it also would be nice if it auto picked the midpoint of the line, but I am really just asking for a way to stream line my project. can anyone help me or does anyone have any suggestions.
-Russ
rad.77676
2005-01-24, 10:38 PM
This should get you started, you may need to adjust text style, layer, color, textsize, etc...
;;; PPL.LSP
;;; 3/21/02
;;; Pipe labeling routine
;;;
(DEFUN C:PPL ()
(font)
(princ "\Select pipe & set rot:")
(COMMAND "STYLE" "ARIALLT" "" "" "" "" "N" "N");set text style
(COMMAND "LAYER" "M" "GEN-P-TXT" "C" "60" "GEN-P-TXT" "" "OSNAP" "NEA");set layer
(COMMAND "DTEXT" "BC" PAUSE (* (GETVAR "USERR5") 0.08) PAUSE);dtext
(COMMAND "COLOR" "BYLAYER" "OSNAP" "NONE")
princ)
)
stig.madsen
2005-01-25, 04:31 PM
Here's a very simple one you can pick apart in order to write your own. Give it a distance from the line, a text string and a text size (or nil if using default size). The latter has no effect if the current text style uses a fixed size, though.
Syntax:
(insTxt 100.0 "HOWDY" 50.0)
means: write HOWDY at 100 units from midpoint of, and perpendicular to, selected line and with size 50.0 (if size is not fixed by the current style)
(insTxt 100.0 "HOWDY" nil)
means: write HOWDY at 100 units from midpoint of, and perpendicular to, selected line and with default size (whether or not size is fixed by the current style)
(defun getEnt (lst / ent)
(setvar "ERRNO" 0)
(while (and (not ent) (/= (getvar "ERRNO") 52))
(cond ((setq ent (car (entsel)))
(if (not (member (cdr (assoc 0 (entget ent))) lst))
(setq ent nil)))))
ent
)
(defun insTxt (dist txt size / rtd ang eline midpt oline perpt)
;; convert radian to degree
(defun rtd (a)(* (/ a pi) 180.0))
(vl-load-com)
(cond ((setq eline (getEnt '("LINE")))
(setq oline (vlax-ename->vla-object eline)
;; get midpoint of line
midpt (vlax-curve-getpointatparam oline
(/ (vlax-curve-getEndparam oline) 2.0))
;; get perp point at dist units from midpoint
perpt (polar midpt (+ (setq ang (angle (vlax-curve-getstartpoint oline)
(vlax-curve-getendpoint oline)))
(/ pi 2.0)) dist)
)
;; check if current style has fixed text style
(cond ((not (zerop (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE"))))))
;; do TEXT command with fixed size
(vl-cmdf "TEXT" "C" "_none" perpt (rtd ang) txt)
)
;; or do TEXT command with specified size, if any
((vl-cmdf "TEXT" "C" "_none" perpt (cond (size) ("")) (rtd ang) txt))
)
)
)
(princ)
)
rstiles
2005-01-28, 04:19 PM
Hey Thanks for getting back to me that is def a good start I however have to apologize for not writing I forgot I had posted because I was working on a different project.
-Russ
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.