Lisp Move the text to the center of the Closed polyline

Lisp Move the text to the center of the Closed polyline

mik501_
Advocate Advocate
568 Views
3 Replies
Message 1 of 4

Lisp Move the text to the center of the Closed polyline

mik501_
Advocate
Advocate

I want moves text to the center of the closing line. multiple text at the same time.

0 Likes
569 Views
3 Replies
Replies (3)
Message 2 of 4

Automohan
Advocate
Advocate

Try this link:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/move-the-mtext-to-the-center-of-the-... 

 

In the code

Change this:

 (0 . "MTEXT")

to this:

 (0 . "MTEXT,TEXT")

 

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 3 of 4

mik501_
Advocate
Advocate

 Thanks, I'm stuck on this problem. It works only with mtext, how to make it work with text?

 

(defun c:foo (/ _l c d r s s2 x)
  ;; RJP » 2020-11-13
  (defun _l (s) (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
  (if (and (setq s (ssget '((0 . "LWPOLYLINE"))))
	   (setq s2 (ssget "_X" '((0 . "*TEXT"))))
	   (setq s (_l s))
	   (setq s2 (mapcar '(lambda (x) (cons (cdr (assoc 10 (entget x))) x)) (_l s2)))
      )
    (foreach e s
      (vla-getboundingbox (vlax-ename->vla-object e) 'c 'd)
      (mapcar 'set '(c d) (mapcar 'vlax-safearray->list (list c d)))
      (if (setq	r
		 (cdr
		   (vl-some '(lambda (x)
			       (if (and (<= (car c) (caar x) (car d)) (<= (cadr c) (cadar x) (cadr d)))
				 x
			       )
			     )
			    s2
		   )
		 )
	  )
	(entmod (append (entget r) (list (cons 10 (polar c (angle c d) (* 0.5 (distance c d)))))))
      )
    )
  )
  (princ)
)

 

0 Likes
Message 4 of 4

Automohan
Advocate
Advocate

See my first post above !

Change:

MText,Text in the code

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution