TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on January 14, 2013, 03:59:08 PM

Title: changing text style of selected text
Post by: andrew_nao on January 14, 2013, 03:59:08 PM
im a bit lazy and in a bit of a hurry
does anyone have a quick and simple lisp to change the text style of selected text from simplex to arial black?

Title: Re: changing text style of selected text
Post by: fixo on January 14, 2013, 06:00:20 PM
Something like this not sure abou:
Code: [Select]
(vl-load-com)
(vla-setfont
  (vla-item
    (vla-get-textstyles
      (setq adoc (vla-get-activedocument
(vlax-get-acad-object))))
    "Standard" ;style
    )
"ARIAL" ;font
:vlax-false ;bold
:vlax-true ;italic
0 ;charset
(+ 2 64) ;font family
)
(vla-regen adoc acallviewports)
Title: Re: changing text style of selected text
Post by: Lee Mac on January 14, 2013, 06:17:32 PM
change the text style of selected text from simplex to arial black?

Text Style or font assigned to a Text Style? (since the two items you mention are font names)

If they are indeed the names of Text Styles:
Code: [Select]
(defun c:foo ( / e i s )
    (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT") (7 . "SIMPLEX"))))
        (repeat (setq i (sslength s))
            (setq e (entget (ssname s (setq i (1- i)))))
            (entmod (subst '(7 . "Arial Black") (assoc 7 e) e))
        )
    )
    (princ)
)
Title: Re: changing text style of selected text
Post by: andrew_nao on January 15, 2013, 11:08:56 AM
thanks for the reply, however neither worked

the style is still simplex


ill just change it over to mtext and do it manually

thanks for the offers :)

btw. i meant font, not style.. sorry for the confusion. i was in a hurry :)

cheers
Title: Re: changing text style of selected text
Post by: CAB on January 15, 2013, 11:42:27 AM
btw. i meant font, not style.. sorry for the confusion. i was in a hurry :)

Andrew you should know that the font in plain text can only be changed by changing the STYLE.
You can create a new Style for your desired font or use an existing style.

Title: Re: changing text style of selected text
Post by: Lee Mac on January 15, 2013, 11:51:55 AM
ill just change it over to mtext and do it manually

 :-o

Just change the font applied to the Text Style and this change will be reflected across all Text objects referencing the style.
Title: Re: changing text style of selected text
Post by: fixo on January 15, 2013, 12:42:27 PM


btw. i meant font, not style.. sorry for the confusion. i was in a hurry :)


Try this code for your style:
 
Code: [Select]
(setq txtstyle (vla-item (vla-get-textstyles adoc) "Standard"));<-- set your style name here
 
  (if (not
(equal (strcase (vla-get-fontfile txtstyle)) "TIMES.TTF"))
    (vl-catch-all-apply
      '(lambda ()
(progn
   (setq fontfile (findfile (strcat (getenv "WINDIR") "\\fonts\\times.ttf")))
   (vla-put-fontfile txtstyle fontfile)
   )
)
      )
    )
Title: Re: changing text style of selected text
Post by: andrew_nao on January 16, 2013, 08:54:33 AM
ill just change it over to mtext and do it manually

 :-o

Just change the font applied to the Text Style and this change will be reflected across all Text objects referencing the style.

thank Lee, however im after just changing the font on selected text not all the text.
Title: Re: changing text style of selected text
Post by: andrew_nao on January 16, 2013, 08:55:51 AM
btw. i meant font, not style.. sorry for the confusion. i was in a hurry :)

Andrew you should know that the font in plain text can only be changed by changing the STYLE.
You can create a new Style for your desired font or use an existing style.

i was trying to get around that, i guess its not possible.

thanks for the reply
Title: Re: changing text style of selected text
Post by: andrew_nao on January 16, 2013, 08:56:53 AM


btw. i meant font, not style.. sorry for the confusion. i was in a hurry :)


Try this code for your style:
 
Code: [Select]
(setq txtstyle (vla-item (vla-get-textstyles adoc) "Standard"));<-- set your style name here
 
  (if (not
(equal (strcase (vla-get-fontfile txtstyle)) "TIMES.TTF"))
    (vl-catch-all-apply
      '(lambda ()
(progn
   (setq fontfile (findfile (strcat (getenv "WINDIR") "\\fonts\\times.ttf")))
   (vla-put-fontfile txtstyle fontfile)
   )
)
      )
    )

thanks fixo ill try this out