Jump to content

Changing line space factor for multiple Mtext


bushlake
 Share

Recommended Posts

Hello.

 

 

I want to change line space factor for all the mtext objects in a hole bunch of drawings by script.

 

 

I found this lisp and it works fine but only by manually selecting the mtext objects.

 

 

(setq vla_mtext (vlax-ename->vla-object (setq mymtext (car (entsel)))))

(vla-put-LineSpacingFactor vla_mtext 0.5)

 

 

Can this lisp be changed so it changes all mtext objects found in the drawing, or is there another way?

 

 

Thanks

Link to comment
Share on other sites

(defun C:test ( / acDoc scf cnt )
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq scf 0.5)
(setq cnt 0)
(vlax-map-collection (vla-get-Block (vla-get-ActiveLayout acDoc)) 
	(function 
		(lambda (x) 
			(and
				(eq (vla-get-ObjectName x) "AcDbMText")
				(eq :vlax-false (vla-get-Lock (vla-item (vla-get-Layers acDoc) (vla-get-Layer x))))
				(vlax-property-available-p x 'LineSpacingFactor)
				(setq cnt (1+ cnt))
				(vla-put-LineSpacingFactor x scf)	
			)
		)
	)
)
(if (> cnt 0) 
	(alert (strcat "\nProceeded " (itoa cnt) " mtext objects! "))
	(alert "\nNo mtext objects are found in this tab! ")
)
(princ)
);| defun |; (or (vlax-get-acad-object) (vl-load-com)) (princ)

 

Or maybe just:

(defun C:test ( / scf SS i )
(princ "\nSelect mtexts to change their \"LineSpacingFactor\": ")
(setq scf 0.5)
(if (setq SS (ssget "_:L" (list (cons 0 "MTEXT"))))
	(repeat (setq i (sslength SS))
		(vla-put-LineSpacingFactor (vlax-ename->vla-object (ssname SS (setq i (1- i)))) scf)
	)
)
(if SS (princ (strcat "\nProceeded " (itoa (sslength SS)) " mtext objects! ")))
(princ)
);| defun |; (or (vlax-get-acad-object) (vl-load-com)) (princ)	

Edited by Grrr
Link to comment
Share on other sites

Another:

(defun c:mtlsp ( / i s )
   (if (setq s (ssget "_X" '((0 . "MTEXT") (-4 . "<>") (44 . 0.5))))
       (repeat (setq i (sslength s))
           (entmod (append (entget (ssname s (setq i (1- i)))) '((44 . 0.5))))
       )
   )
   (princ)
)

Link to comment
Share on other sites

I can see the next question oh I want a different spacing

 

(defun c:mtlsp ( / i s rnum)
   (setq rnum (getreal "\nEnter spacing <Cr> = 0.5 "))
   (if (= rnum nil)(setq rnum 0.5))
   (if (setq s (ssget "_X" (list (cons 0 "MTEXT") (cons -4  "<>") (cons 44 rnum))))
       (repeat (setq i (sslength s))
           (entmod (append (entget (ssname s (setq i (1- i)))) (list (cons 44 rnum))))
       )
   )
   (princ)
)

Link to comment
Share on other sites

Another:
(defun c:mtlsp ( / i s )
   (if (setq s (ssget "_X" '((0 . "MTEXT") (-4 . "<>") (44 . 0.5))))
       (repeat (setq i (sslength s))
           (entmod (append (entget (ssname s (setq i (1- i)))) '((44 . 0.5))))
       )
   )
   (princ)
)

 

This code solved the problem perfectly, thanks again!!!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...