TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cmwade77 on November 23, 2021, 08:02:44 PM
-
The attached routine (FontSub and FontRemap commands are the issues) are supposed to remap all fonts and styles that use RomanS or RomanS_New to arial.ttf, but sometimes it remaps to seemingly random fonts, anyone have any ideas why?
-
Just a guess here quickly looking over the code. (stripmtext SS "F") seems to be stripping the font of mtext and changing it to whatever the current text style font is.
If you run that command and select some mtext you can just uncheck font. make sure you have remember checked and should fix the problem.
Maybe the F means font? idk maybe remove that line if its still a problem.
-edit-
yep "F" = Font
-
Curious why you added these functions at the end of the StripMtext code.
FontSub, CivilSub and FontRemap are supposed to remap a lot more fonts and styles than just RomanS or RomanS_New. Are you sure those are random? Can you list any that were modified that shouldn't have been?
-
Curious why you added these functions at the end of the StripMtext code.
FontSub, CivilSub and FontRemap are supposed to remap a lot more fonts and styles than just RomanS or RomanS_New. Are you sure those are random? Can you list any that were modified that shouldn't have been?
Those are also changed, it is just the RomanS and RomanS_New that don't always get changed correctly for some reason. Basically, we are in the process of a CAD Standards changeover to change to TTF due to new DSA requirements that anywhere we reference a sheet, there must be a link and some other plan checkers that now require all text be machine readable, so easiest to do a blanket change.
-
Just a guess here quickly looking over the code. (stripmtext SS "F") seems to be stripping the font of mtext and changing it to whatever the current text style font is.
If you run that command and select some mtext you can just uncheck font. make sure you have remember checked and should fix the problem.
Maybe the F means font? idk maybe remove that line if its still a problem.
-edit-
yep "F" = Font
But I wouldn't think it should be changing the text style definition itself, just removing font overrides from the mtext, which is what I want it to do.
And yes, I am sure it is random, as it sometimes changes to some Aribac font or something like that, which makes no sense.
-
Can you share how the mtext is remapped to random fonts? Is that in the edit box that you're seeing that?
When I have mtext formatting problems, I edit the text with notepad/textpad by changing the MTEXTED variable temporarily so I can see all the raw codes. (I have a special edit routine that does this automatically.)
Also curious how you are managing to add links to sheet references. I'd like to do that but I don't know an easy efficient way to do so.
-
The mtext isn't the issue, it is the style definition.
After running the command, I type style and check the text style, it will have different fonts assigned randomly to the style.
-
got it, was confused by stripmtext lisp beginning your file
On Bricscad v15, this worked for me:
: (tblnext "style" T)
((0 . "STYLE") (2 . "Standard") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . "Calibri") (4 . ""))
: (subfont "calibri.ttf" "arial.ttf")
Changing: calibri.ttf to: arial.ttf
: STYLE
: (tblnext "style" T)
((0 . "STYLE") (2 . "Standard") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . "C:\\WINDOWS\\fonts\\arial.ttf") (4 . ""))
Though I don't like that the font path is hard-coded into the style. I assume that will cause conflicts when the drawing is opened with different OS configuration.
If you have an example drawing with the fonts you want to check, post and I can test.
-
got it, was confused by stripmtext lisp beginning your file
On Bricscad v15, this worked for me:
: (tblnext "style" T)
((0 . "STYLE") (2 . "Standard") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . "Calibri") (4 . ""))
: (subfont "calibri.ttf" "arial.ttf")
Changing: calibri.ttf to: arial.ttf
: STYLE
: (tblnext "style" T)
((0 . "STYLE") (2 . "Standard") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.09375) (3 . "C:\\WINDOWS\\fonts\\arial.ttf") (4 . ""))
Though I don't like that the font path is hard-coded into the style. I assume that will cause conflicts when the drawing is opened with different OS configuration.
If you have an example drawing with the fonts you want to check, post and I can test.
Unfortunately, the one that I am having issues with I can't legally share, let me see if I can find another file that is doing this.
-
Just erase everything but don't purge the text styles? Also OK to PM me.
-
Just erase everything but don't purge the text styles? Also OK to PM me.
I sent you a PM.
-
I had to edit the lisp to point to where the fonts could be found on my system, some were at "C:\\Users\\Dan\\AppData\\Local\\Microsoft\\Windows\\Fonts\\"
Also windows renamed my font to have a hyphen, while your lisp did not: "Helvetica-Bold.ttf"
After that, using c:fontsub - it seemed to work, attached are screen shots of the styles before and after. c:fontremap worked also, only changed one other style so I didn't save an image.
sorry - no ideas. I would work through the code of a trouble font substitution and see what happens to look for the bug.
also, had to use DWG TrueView to convert down to v2013 so I could open. No idea if that changed anything.
-
I've always used T.Willey's Merge text styles (or change text styles) for the Text Styles then used StripMtext code as needed on Mtext.
http://www.theswamp.org/index.php?topic=17659.0;all
-
If I list the font with LISP, it is claiming to use the correct font, but the style dialog box does not show the font being used. Here is a video:
https://www.awesomescreenshot.com/video/6210540?key=9b078b584c20187b0603a4fb050f9d0f
Here is updated code:
(vl-load-com)
(defun C:FontSub ( / doc)
;Format for List: <Font to Remap To> <All Fonts to remap>
(subfont
(list
(list "arial.ttf" "romans.shx" "romand.shx" "simplex.shx" "osafrac.shx" "txt.shx" "RomanS_New.ttf")
;(list "Helvetica Bold.ttf" "helvbld.shx" "hlvm1d.shx" "helvm2.shx" "x-hlvm1d.shx")
)
)
)
(defun SubFont (FontList / doc Ct FontChangeList FontToChange FontToChangeBase DestinationFontName AllStyles DestinationFontBase CurrentStyleFile CurrentStyleBase CurrentStyleName tStyle)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark doc)
(foreach FontChangeList FontList
(setq Ct 1
DestinationFontName (nth 0 FontChangeList)
)
(if (not (setq DestinationFontPath (findfile (strcat (getenv "WINDIR") "\\fonts\\" DestinationFontName))))
(setq DestinationFontPath (findfile DestinationFontPath))
)
(if DestinationFontPath
(progn
(setq DestinationFontBase (vl-filename-base DestinationFontPath))
(while (< Ct (length FontChangeList))
(setq FontToChange (strcase (nth Ct FontChangeList))
FontToChangeBase (strcase (vl-filename-base FontToChange))
Ct (+ Ct 1)
AllStyles (vla-get-textstyles doc)
)
(vlax-for tStyle AllStyles
(setq CurrentStyleName (vla-get-name tStyle)
CurrentStyleFile (vla-get-fontfile tStyle)
CurrentStyleBase (vl-filename-base CurrentStyleFile)
)
(if (and (or (= (strcase CurrentStyleFile) FontToChange) (= (strcase CurrentStyleBase) FontToChangeBase)) (not (wcmatch CurrentStyleName "*|*")))
(progn
(vla-put-fontfile tStyle DestinationFontPath)
(princ "\nChanged ") (princ CurrentStyleName) (princ " to ")(princ (vla-get-fontfile tStyle))(princ " as defined ")(princ DestinationFontBase)(princ "\n")
)
)
)
);end while
);end Progn
);end if
);end foreach
(c:ListFonts)
(vla-endundomark doc)
(princ)
);end defun
(defun c:ListFonts (/ AllStyles doc tStyles)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
AllStyles (vla-get-textstyles doc)
)
(vlax-for tStyle AllStyles
(if (not (wcmatch (vla-get-name tstyle) "*|*"))
(progn
(princ "\nStyle: ")(princ (vla-get-name tstyle)) (princ " -> Font: ")(princ (vla-get-fontfile tStyle))
)
)
)
)
EDIT: It appears the correct font is getting used, it just displays wrong in the User Interface elements, such as the Style dialog and the ribbon when editing text.
-
I've always used T.Willey's Merge text styles (or change text styles) for the Text Styles then used StripMtext code as needed on Mtext.
http://www.theswamp.org/index.php?topic=17659.0;all
His is a lot more complex than what I want, I simply want to change the fonts being used, for a variety of reasons I can't merge styles, as the style names have to remain for other LISP Compatibility.
-
EDIT: It appears the correct font is getting used, it just displays wrong in the User Interface elements, such as the Style dialog and the ribbon when editing text.
Is this true after saving & reopening the drawing?
Alternately I wonder if you ran through the -STYLE command, entering "" to accept current settings, would that trigger a refresh of a style displaying incorrectly?
-
I believe that I have found a solution that works in AutoCAD as well as BricsCAD, please see attached. It turned out, AutoCAD also needs SetFont.
Edit: Updated again due to a typo.
-
EDIT: It appears the correct font is getting used, it just displays wrong in the User Interface elements, such as the Style dialog and the ribbon when editing text.
Is this true after saving & reopening the drawing?
Alternately I wonder if you ran through the -STYLE command, entering "" to accept current settings, would that trigger a refresh of a style displaying incorrectly?
Yes, it is true after saving and reopening, I finally found where the issue was in AutoCAD, BricsCAD was more robust at handling the change than AutoCAD was, AutoCAD needed to use vla-setfont.