Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Text on line lisp

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
will.wydock
1633 Views, 3 Replies

Text on line lisp

I am not strong at modifying lisp. I have the routine below, it works fine except that when any type of lines are drawn at an angle over 180 dgrees. Then it puts in text upside down. I know that logically i should have an if statement that says if the angle is 180 or greater that i should subtract 180 to get the angle i should use. Any help would be greatly appreciated.

 

Thanks,

 

 

(vl-load-com)
(defun c:gcs-TextinLine()
(glt-TextinLine 0.09375 )
(princ)
)

(defun glt-TextinLine (standtext / _cmdecho _osmode lineent lineobj p1 lineangle textheight
textent)
;you need to clear out old variables

;(rtd ) this subroutine converts radians to degrees.
(defun rtd (a) (/ (* a 180.0) pi))

;(dgtr ) this subroutine converts degrees to radians
(defun dtr (a) (* pi (/ a 180.0)))

(setq _cmdecho (getvar "cmdecho"))
;save the user's settings and restore at end
(setvar "cmdecho" 0)
(setq lineent (entsel "\nSelect Line at location of text string"))
;select the line
(setq lineobj (vlax-ename->vla-object (car lineent)))
;get the line object
(setq p1 (cadr lineent))
;get the point where the user clicked
(setq lineangle (rtd (vla-get-angle lineobj)))
;get the angle
(setq textheight (* (getvar "dimscale") standtext))
;calculate the text height
(command ".dtext" "j" "mc" p1 textheight lineangle)
;start the text command
and fill in the values
(while (eq 1 (logand 1 (getvar "CMDACTIVE")))
;wait til the command is no longer active
(command pause)
)
(setq textent (entlast))
;get the text entity
(command ".trim" textent "" lineent "")
;trim the line using the text
(setvar "cmdecho" _cmdecho)
;restore the user's setting
(princ)
)

 

3 REPLIES 3
Message 2 of 4
Shneuph
in reply to: will.wydock

You need to change the ;get the angle line:

 

(if (> (setq lineangle (cvunit (vla-get-angle lineobj)"radian" "degree")) 180)
  (setq lineangle (- lineangle 180))
);end if

 

Also cvunit is built in if you don't want to use rtd.  You can even edit a file with the unit names and conversion factors.  I'd have to look that up again where it is.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 3 of 4
Shneuph
in reply to: Shneuph

Actually, that is what you asked for.. but this may get you closer to the outcome you want.

 

(setq lineangle (rtd (vla-get-angle lineobj)))
(if (and (> lineangle 90)(< lineangle 270))
(setq lineangle (+ lineangle 180))
);if

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 4
Ranjit_Singh2
in reply to: Shneuph

I also prefer that any vertical text is labeled facing to the right. See below fix.

(vl-load-com)
(defun c:gcs-textinline () (glt-textinline 0.09375) (princ))
(defun glt-textinline  (standtext / _cmdecho _osmode lineent lineobj p1 lineangle textheight textent)
 (defun rtd (a) (/ (* a 180.0) pi))
 (defun dtr (a) (* pi (/ a 180.0)))
 (setq _cmdecho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (setq lineent (entsel "\nSelect Line at location of text string"))
 (setq lineobj (vlax-ename->vla-object (car lineent)))
 (setq p1 (cadr lineent))
 (setq lineangle (rtd (vla-get-angle lineobj)))
 (setq textheight (* (getvar "dimscale") standtext))
 (command ".dtext" "j" "mc" p1 textheight (if (and (>= 270 lineangle) (> lineangle 90)) (- lineangle 180) lineangle))
 (while (eq 1 (logand 1 (getvar "CMDACTIVE"))) (command pause))
 (setq textent (entlast))
 (command ".trim" textent "" lineent "")
 (setvar "cmdecho" _cmdecho)
 (princ))

text_in_line.gif

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost