Move TEXT or MTEXT to a predetermined distance from a line

Move TEXT or MTEXT to a predetermined distance from a line

Lineabove
Collaborator Collaborator
766 Views
3 Replies
Message 1 of 4

Move TEXT or MTEXT to a predetermined distance from a line

Lineabove
Collaborator
Collaborator

Question,

 

I see a number of drawings where the Text (or Mtext) is either placed directly on a line or very close to the line and of course when plotting the Text may be unintelligble.

 

Anybody have a lisp to share where:

Determine the desired distance from the line.

Pick the Text

Pick the Line

The Text would justification change to Top Center or Bottom Centre depending on the orientation to the line

And then the Text would move to the predetermined distance from the line.

 

This would certainly help in cleaning up some drawings I recieve from Consultants.

 

 

Any help would be appreciated.

 

0 Likes
Accepted solutions (1)
767 Views
3 Replies
Replies (3)
Message 2 of 4

devitg
Advisor
Advisor

Please upload a sample dwg , with a BEFORE and AFTER 

0 Likes
Message 3 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this code... it rotates text along selected line as well. You can turn of this by commneting the code lines (put semicolon in front of all those lines)

 

Spoiler
(defun c:TextLineDist ( / ss pl d i en pc pt pp an)
  (if (and (setq ss (ssget '((0 . "*TEXT"))))
	   (setq pl (car (entsel "\nSelect line to enclose to: ")))
	   (wcmatch (cdr (assoc 0 (entget pl))) "*LINE,ARC,CIRCLE,RAY")
	   (wcmatch (cdr (assoc 0 (entget pl))) "~MLINE")
	   (setq d (getdist "\nDistance from line: "))
	   )
    (progn
      (if (not acet-tjust) (load "acettxt.lsp"))
      (acet-tjust ss "Middle")
      (repeat (setq i (sslength ss))
	(if (setq ed (entget (setq en (ssname ss (setq i (1- i)))))
		  pc (if (= "TEXT" (cdr (assoc 0 ed))) 11 10)
		  pt (cdr (assoc pc ed))
		  pp (vlax-curve-getClosestPointTo pl pt)
		  an (angle '(0 0 0) (vlax-curve-getFirstDeriv pl (vlax-curve-getParamAtPoint pl pp))))
	  (entmod (append ed
			  (list (cons pc (polar pp (angle pp pt) d))
				(cons 50 (setq an (if (= pc 11) ; comment from here
						    an  
						    (- an (angle '(0 0 0) (getvar 'UCSXDIR))))
					       an (if (< an 0)
						    (+ an (* 2 PI))
						    an)	
					       an (if (and (<= an (* 1.5 pi))
							   (> an (* 0.5 pi)))
						    (+ an pi)
						    an))) 	; to here
				)))))))
  (princ)
  )
Message 4 of 4

Lineabove
Collaborator
Collaborator

BeekeeCZ

 

That code works wonderful, I am very impressed.

 

This will save a greta deal of time and even better, the drawing will look consistent.

 

Thank you very much.

 

 

0 Likes