Text and mtext offset

Text and mtext offset

jessicatyler0007
Advocate Advocate
2,042 Views
8 Replies
Message 1 of 9

Text and mtext offset

jessicatyler0007
Advocate
Advocate

Hi All,

 Help me that I need to keep the text and Mtext at some distance from the polyline, and also rotate the text,Mtext along the polyline, is it possible?
The text has to manually input the distance from the polyline, I put the text in the test drawing at a distance of 100.

0 Likes
Accepted solutions (2)
2,043 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

Here's one of my working tools.

 

(vl-load-com)
(defun c:MoveFromLine ( / ss pl i en ed et pc pt pp an fn tmp)
  
  (or *mtl-ds*
      (setq *mtl-ds* 0.))
  
  (if (and (setq ss (ssget '((0 . "LINE,LWPOLYLINE,ARC,CIRCLE,RAY,*TEXT,INSERT"))))
	   (progn
	     (while (not (progn
			   (initget "Copy")
			   (setq tmp (getdist (strcat "\nDistance from line [Copy] <" (rtos *mtl-ds* 2 2) ">: ")))
			   (cond ((not tmp))
				 ((= tmp "Copy")
				  (setq fn entmake)
				  nil)
				 ((setq *mtl-ds* tmp))))))
	     *mtl-ds*)
	   (or (and (setq pl (acet-ss-ssget-filter ss '((0 . "LINE,LWPOLYLINE,ARC,CIRCLE,RAY"))))
		    (setq pl (ssname pl 0)))
	       (and (setq pl (car (entsel "\nSelect a poline: ")))
		    (or (wcmatch (cdr (assoc 0 (entget pl))) "LINE,LWPOLYLINE,ARC,CIRCLE,RAY")
			(prompt "\nError: Wrong selection. Must be LINE,LWPOLYLINE,ARC,CIRCLE or RAY"))))
	   (setq ss (acet-ss-ssget-filter ss '((0 . "*TEXT,INSERT"))))
	   )
    (repeat (setq i (sslength ss))
      (if (setq en (ssname ss (setq i (1- i)))
		ed (entget en)
		et (cdr (assoc 0 ed))
		pc (if (and (= "TEXT" et)
			    (/= 0 (cdr (assoc 72 ed)) (cdr (assoc 73 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))))
	((cond (fn) (entmod))
	  (append ed
		  (list (cons pc (polar pp (+ an (/ pi 2)) *mtl-ds*))
			(cons 50 (setq an (if (= et "MTEXT")
					    (- an (angle '(0 0 0) (getvar 'UCSXDIR)))
					    an)
				       an (if (< an 0)
					    (+ an (* 2 pi))
					    an)
				       an (if (and (<= (if (= et "MTEXT")
							 an
							 (angle (trans '(0 0 0) 0 1) (trans (polar '(0 0 0) an 1) 0 1))) ; readable text mtext ucs
						       (* 1.5 pi))
						   (>  (if (= et "MTEXT")
							 an
							 (angle (trans '(0 0 0) 0 1) (trans (polar '(0 0 0) an 1) 0 1)))
						       (* 0.5 pi)))
					    (+ an pi)
					    an)))))))))
  (princ)
  )

 

Message 3 of 9

pbejse
Mentor
Mentor
Accepted solution

@jessicatyler0007 wrote:

The text has to manually input the distance from the polyline, I put the text in the test drawing at a distance of 100.


Quick one

(defun c:bugspray (/ d ref ss i e ent ipt npt ang)
  (if (and (setq d (getdist "\nEnter distance from reference line :"))
	   (princ "\nSelect reference line: ")
	   (setq ref (ssget "_+.:S:E" '((0 . "LWPOLYLINE"))))
	   (setq ref (ssname ref 0))
	   (princ "\nSelect the bugs: ")
	   (setq ss (ssget ":L" '((0 . "TEXT,MTEXT"))))
      )
    (repeat (setq i (sslength ss))
      (setq e (ssname ss (setq i (1- i))))
      (setq ent (entget e))
      (setq ipt (cdr (assoc 10 ent)))
      (setq npt (vlax-curve-getclosestpointto ref ipt))
      (setq ang	(angle '(0.0 0.0 0.0)
		       (vlax-curve-getfirstderiv
			 ref
			 (vlax-curve-getparamatpoint ref npt)
		       )
		)
      )
      (entmod
	(append	ent
		(list
		  (cons 10 (polar npt (+ (/ pi 2.0) ang) d))
		  (cons 50 ang)
		)
	)
      )
    )
  )
  (princ)
)

HTH

 

Command: Bugspray

Enter distance from reference line :500
Select reference line:
Select the bugs:
Select objects: Specify opposite corner: 17 found

 

 

Message 4 of 9

jessicatyler0007
Advocate
Advocate

@ВeekeeCZ @pbejse ,

your both lisp code are excellent, I am grateful to you.

Thank you very much

0 Likes
Message 5 of 9

jessicatyler0007
Advocate
Advocate

@ВeekeeCZ @pbejse ,

Please add another small option of text rotation to yes or no.

0 Likes
Message 6 of 9

pbejse
Mentor
Mentor

@jessicatyler0007 wrote:

@ВeekeeCZ @pbejse ,

Please add another small option of text rotation to yes or no.


HYG [ refer to attached lisp file ]

......      
(initget "Yes No")
      (if (null	(setq opt (getkword "\nRotate Text [Yes/No] <Yes>: "))
	  )
	(setq opt "Yes")
      )
......
(cons 50
 (if (eq opt "Yes")
   ang
   rot
 )
)

HTH

 

0 Likes
Message 7 of 9

jessicatyler0007
Advocate
Advocate

@pbejse 

Thank you so much for your Help!!!

0 Likes
Message 8 of 9

ВeekeeCZ
Consultant
Consultant

Since both routines are pretty much the same ... the same suggestion would be applicable to my routine either.

Nice suggesting pbe, it's two in one! What productivity!

Message 9 of 9

marius_n_costea
Explorer
Explorer

Hello

 

It's and awesome lisp, I've been looking for such a lisp for a long time. Is it possible to add the option to move to 3D POLYLINES as well please? I don't know how to adjust the lisp.

 

Kind Regards

Marius

0 Likes