+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Forum Newbie
    Discipline
    Manufacture
    bushlake's Discipline Details
    Occupation
    Electrical Engineer
    Discipline
    Manufacture
    Using
    AutoCAD 2015
    Join Date
    Oct 2016
    Location
    Sweden
    Posts
    2

    Default Changing line space factor for multiple Mtext

    Registered forum members do not see this ad.

    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

  2. #2
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,067

    Default

    Code:
    (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:
    Code:
    (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)
    Last edited by Grrr; 26th Oct 2016 at 05:20 pm.

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Another:
    Code:
    (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)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #4
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,738

    Default

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

    Code:
    (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)
    )
    A man who never made mistakes never made anything

  5. #5
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,067

    Default

    Quote Originally Posted by BIGAL View Post
    I can see the next question oh I want a different spacing
    BIGAL - the Prophet

  6. #6
    Forum Newbie
    Discipline
    Manufacture
    bushlake's Discipline Details
    Occupation
    Electrical Engineer
    Discipline
    Manufacture
    Using
    AutoCAD 2015
    Join Date
    Oct 2016
    Location
    Sweden
    Posts
    2

    Smile Solved!

    Quote Originally Posted by Lee Mac View Post
    Another:
    Code:
    (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!!!

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Registered forum members do not see this ad.

    You're most welcome
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Changing font and width factor of multiple text styles
    By sala in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 18
    Last Post: 19th Jul 2016, 08:21 am
  2. Replies: 1
    Last Post: 7th Jul 2015, 10:56 am
  3. Changing Font of Multiple MText
    By acad2012 in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 4
    Last Post: 17th Jul 2012, 05:17 pm
  4. changing line space factor for existing text
    By Hickoz_bro in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 28th Mar 2008, 01:46 pm
  5. Clicking into Model Space in viewport changing the zoom factor?
    By Match in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 23rd Jun 2007, 12:33 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts