ziofel Posted July 22, 2010 Share Posted July 22, 2010 Hi everyone, I need to write a function in Visual Lisp that will place text over a line or pline . The text would be relative in size or length to the line selected (this is not mandatory but nice) I know there are a lot of functions on here that will take text and align it with curves or lines at different angles but all I need is one that is simple and lined up with your basic horizontal line of any length. Basically like this. TEXT HERE User selects line then user types in text then text is placed on line. Thanks Raff Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 22, 2010 Share Posted July 22, 2010 Have you started working on this or just looking for a handout? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 22, 2010 Share Posted July 22, 2010 TEXT HERE Raff Have you tried the UNDERLINE Button in MTEXT or the %%u in TEXT commands ? That's would be helpful. Tharwat Quote Link to comment Share on other sites More sharing options...
ziofel Posted July 22, 2010 Author Share Posted July 22, 2010 Have you started working on this or just looking for a handout? Yes I have started and maybe should of placed the file as I have it. (defun c:textline (/ insertpoint textinput) (setq insertpoint (getpoint "\nSelect text location: ")) ; waits for user for input (command "text" insertpoint 2 0 (strcat (princ textinput))) (princ) ) Have you tried the UNDERLINE Button in MTEXT or the %%u in TEXT commands ? That's would be helpful. Tharwat No, I want to select the line and text gets placed on top of it. The above works but need to adjust text a little above line and text being relative to size of line. The other problem with this is that it asks for a point to insert text and I want to select line and place text over line. Quote Link to comment Share on other sites More sharing options...
lpseifert Posted July 22, 2010 Share Posted July 22, 2010 you can pick this apart if you'd like ;;;Label storm pipe size LPS 2010-02-04 (defun c:lblstsize (/ ent midpt entname obj mid-param beg-pt end-pt ang ins-pt) (vl-load-com) (setq temperr *error* *error* errortrap varlst '("cmdecho") oldvar (mapcar 'getvar varlst) ) (setvar "cmdecho" 0) (defun dtr (a) (* pi (/ a 180.0))) (command "UCS" "W") (setq ent (entsel "\nSelect pipe: ") midpt (osnap (cadr ent) "mid") entname (car ent) obj (vlax-ename->vla-object entname) mid-param (vlax-curve-getParamAtPoint obj midpt) beg-pt (vlax-curve-getPointAtParam obj (fix mid-param)) end-pt (vlax-curve-getPointAtParam obj (1+ (fix mid-param))) ang (angle beg-pt end-pt)) (if (and (> ang 1.74533) (< ang 4.53786)) (setq ang (angle end-pt beg-pt)) ) (setq ins-pt (polar midpt (+ ang (/ pi 2)) (* (getvar "dimscale")0.125))) (if (not (tblsearch "layer" "st-txt")) (command "-layer" "m" "ST-TXT" "C" "130" "ST-TXT" "")) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 8 "ST-TXT") (cons 10 ins-pt) (cons 1 (getstring T "\nEnter Pipe size: ")) (cons 71 5) (cons 50 ang) (cons 7 "Simplex") (cons 40 (* (getvar "dimscale") 0.1)) ) ) (setvar "cmdecho" 1) (command "UCS" "P") (princ) );defun (defun errortrap (msg) (if oldvar (mapcar 'setvar varlst oldvar)) (setq *error* temperr) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n<< Error: " msg " >>")) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
ziofel Posted July 22, 2010 Author Share Posted July 22, 2010 What are the cons inside a list used for? I don't know a lot about Lisp. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 22, 2010 Share Posted July 22, 2010 Creates a dotted pair. Read the Dev Help in the VLIDE on cons. Quote Link to comment Share on other sites More sharing options...
fixo Posted July 22, 2010 Share Posted July 22, 2010 Hi everyone, I need to write a function in Visual Lisp that will place text over a line or pline .The text would be relative in size or length to the line selected (this is not mandatory but nice) I know there are a lot of functions on here that will take text and align it with curves or lines at different angles but all I need is one that is simple and lined up with your basic horizontal line of any length. Basically like this. TEXT HERE User selects line then user types in text then text is placed on line. Thanks Raff Try this also ;; lab.lsp ;; labeling lines/polylines (vl-load-com) (defun C:LAB (/ acsp ang deriv dist dist1 dist2 ent mpt obj para pickpt txt txtpt) (setq acsp (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))) ) (while (setq ent (entsel "\nSelect line / pline: ")) (setq obj (vlax-ename->vla-object (car ent)) pickpt (vlax-curve-getclosestpointto obj (cadr ent)) para (vlax-curve-getparamatpoint obj pickpt) mpt (vlax-curve-getpointatparam obj (+ 0.5 (fix para))) txtpt (vlax-3d-point mpt) deriv (vlax-curve-getfirstderiv obj (vlax-curve-getparamatpoint obj pickpt)) ) (if (zerop (cadr deriv)) (setq ang 0) (setq ang (- (/ pi 2) (atan (/ (car deriv) (cadr deriv))))) ) (if (eq "AcDbLine" (vla-get-objectname obj)) (setq dist (vla-get-length obj)) (progn (setq dist1 (vlax-curve-getdistatparam obj (fix para)) dist2 (vlax-curve-getdistatparam obj (1+ (fix para))) dist (abs (- dist2 dist1))))) (setq txt (vla-addtext acsp (rtos dist 3 2) txtpt 15.0)) ;<-- change text height (currently 15.0) here (vla-put-alignment txt acalignmentbottomcenter) (vla-put-textalignmentpoint txt txtpt) (if (< (/ pi 2) ang (* pi 1.5)) (setq ang (+ pi ang)) ) (vla-put-rotation txt ang)) (princ) ) (princ "\n >> Start command with LAB >>") (prin1) ~'J'~ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.