TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: w64bit on May 12, 2021, 08:23:28 AM

Title: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: w64bit on May 12, 2021, 08:23:28 AM
How can I change using lisp the font txt.shx to simplex.shx (width 0.80) in Text Styles?
It could be more than one text style using txt.shx.
Title: Re: Change txt font to simplex in Text Styles
Post by: kpblc on May 12, 2021, 10:57:05 AM
I didn't check this code.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:t1 (/ adoc)
  2.     (if (and (/= (vla-get-fontfile item) "") (/= (vla-get-fontfile item) "txt.shx"))
  3.       (vla-put-fontfile item "simplex.shx")
  4.     ) ;_ end of if
  5.   ) ;_ end of vlax-for
  6.   (vla-endundomark adoc)
  7.   (princ)
  8. ) ;_ end of defun
Title: Re: Change txt font to simplex in Text Styles
Post by: w64bit on May 12, 2021, 12:02:12 PM
it's loading and it's running without errors.
Unfortunately it does not change the font.
Title: Re: Change txt font to simplex in Text Styles
Post by: Tharwat on May 12, 2021, 12:42:21 PM
change the not equal  to equal :
Code - Auto/Visual Lisp: [Select]
  1. (/= (vla-get-fontfile item) "txt.shx") ;| to be |; (= (vla-get-fontfile item) "txt.shx")
Title: Re: Change txt font to simplex in Text Styles
Post by: w64bit on May 12, 2021, 01:37:15 PM
Thank you very much kpblc and Tharwat.
Title: Re: Change txt font to simplex in Text Styles
Post by: MSTG007 on May 12, 2021, 01:41:52 PM
Could i ask if you wanted to change all fonts within the text styles?

I am guessing i would change:

Code: [Select]
(if (and (/= (vla-get-fontfile item) "") (/= (vla-get-fontfile item) "")) ;;remove the font name?
Just curious!
Title: Re: Change txt font to simplex in Text Styles
Post by: w64bit on May 12, 2021, 02:02:01 PM
@MSTG007: I want to change the font only for the text styles which are using txt.shx.
Title: Re: Change txt font to simplex in Text Styles
Post by: MSTG007 on May 13, 2021, 08:05:16 AM
lol Sorry i was not clear.

I did not know what I would have needed to modify to get it to change all text styles within a dwg to the txt.shx.
Title: Re: Change txt font to simplex in Text Styles
Post by: w64bit on May 13, 2021, 08:17:30 AM
Tried with simplex instead simplex.txt. No change.
Title: Re: Change txt font to simplex in Text Styles
Post by: w64bit on May 26, 2021, 11:58:54 AM
I attached the drawing with 3 fonts to change the style's font to simplex.shx.
Can anyone test the attached lisp. On my machine it's not working.
Thanks
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: Lonnie on May 26, 2021, 12:59:47 PM
Fairly similar

http://www.theswamp.org/index.php?topic=55991.msg599756#msg599756

Code: [Select]

;set fonts all fonts to arial.
 
 (if (findfile (setq f (strcat (getenv "windir") "\\Fonts\\Arial.ttf")))
    (progn
      (vlax-for s (vla-get-textstyles (setq doc (vla-get-activedocument (vlax-get-acad-object))))




        (vla-put-fontfile s f)
        (vla-put-width s 1.0)
        ;; RJP » 2020-04-29
        (vla-setfont s "Arial" :vlax-false :vlax-false 0 34)
      )
      (vla-regen doc acallviewports)
    )
  )

Worked for me.
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: w64bit on May 26, 2021, 01:14:41 PM
This code it's good to change all fonts but I want to change only the styles having txt.shx, monotxt.shx, monotxt8.shx fonts, and not touching the rest.
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: Lonnie on May 26, 2021, 01:16:14 PM
Perhaps next time I'll read the post a little better.
 :uglystupid2:
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: tombu on May 29, 2021, 09:40:24 AM
Usually whenever I get outside drawing with a huge list of odd text styles I've always used T.Willey's Merge text styles to clean them up and make them more readable. http://www.theswamp.org/index.php?topic=17659.0;all
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: w64bit on May 29, 2021, 10:38:21 AM
MTS it's very good. Thank you.
The main problem remains: I have a couple of hundreds DWG with this font issue and I cannot find a way to fix it.
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: BIGAL on May 29, 2021, 08:31:37 PM
Try this on a dwg

(vlax-for ts (vla-get-textstyles  (vla-get-activedocument (vlax-get-acad-object)))
(if (= (vla-get-FontFile ts ) "Txt.shx")
(vla-put-FontFile ts "Simplex.shx")
)
)

Using a script can run this very simple lisp program, for 500 dwgs accoreconsole is the way to go you have a script that loads the lisp.
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: w64bit on May 30, 2021, 05:03:13 AM
error: bad argument type: VLA-OBJECT nil
I changed s to ts in second line.
No change to any font.
You can try on the file attached.
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: Tharwat on May 30, 2021, 08:08:37 AM
The same codes that posted by kpblc with the mods that indicated to in my first post.
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: w64bit on May 30, 2021, 08:22:53 AM
I think my AutoCAD install has something wrong. On another computer it's OK.
Can you please tell me how I can add monotxt and monotxt8 in the same code?
Thank you
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: Tharwat on May 30, 2021, 08:41:08 AM
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ adoc fnt)
  2.   ;; kpblc - modified by Tharwat
  3.     (if (and (/= (setq fnt (vla-get-fontfile item)) "")
  4.              (wcmatch fnt "txt.shx,monotxt.shx,monotxt8.shx")
  5.              )
  6.       (vla-put-fontfile item "simplex.shx")
  7.     ) ;_ end of if
  8.   ) ;_ end of vlax-for
  9.   (vla-endundomark adoc)
  10.   (vla-regen adoc acallviewports)
  11.   (princ)
  12. ) ;_ end of defun
  13.  
  14.  
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: w64bit on May 30, 2021, 10:04:02 AM
Thank you all very much.
Title: Re: Change TXT.shx to SIMPLEX.shx in all Text Styles
Post by: BIGAL on May 30, 2021, 07:47:25 PM
Fixed the typo in the code had ts and s.