MstnFontConfig.xml Wildcards

I am a big fan of using the MstnFontConfig file to minimize the number of fonts available for selection in the text editor.

Sometimes there are many variations on a particular font, for example, "Highway B", "Highway C", "Highway C Plus", etc.

Is there any way to use wildcards in this process?  For example, can I type "Highway*" and have all of the Highway fonts load?

Here is a spoiler for you, unless I'm missing an escape character, I've tried Highway*, Highway%, I've even used RegEx expressions, none of them seem to work.

Any insight is appreciated.

  • Just out of curiosity: why do you have those variations of fonts? iI it just the name and the fonts are really different or are they pretty much slight variations?

  • Hi Tim,

    Unfortunately I don't think this approach will work in this instance, according to this link, the <Name> node is a "Comma-separated list of TrueType font names to which these settings apply." therefore it sounds to me like you have to explicitly provide a list of font names to show or hide.

    However, this task can be made easier:

    1. Below is some Powershell code:
      [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
      (New-Object System.Drawing.Text.InstalledFontCollection).Families | Out-File -FilePath "C:\FontList.txt"

    2. Open up Notepad, Copy and paste the code into a document and save it with a .ps1 extension e.g. List TTF Fonts.ps1
    3. Right-click the ps1 file and choose 'Run with Powershell'
    4. Your TTF font names will be written to a text file at the root of your C:\ (you can edit the script to change to a path of your preference)
    5. Open the text file, copy the contents (except the Name header and any spaces) and paste into an Excel worksheet
    6. Select Cell A1 and then press Ctrl+Shift+Down Arrow to select all the font names, then press copy
    7. Select Cell B1, press Paste Special and choose Transpose
    8. Delete Column A

    At this point you now need to make a decision, you either make a list of all the fonts you want to be visible, or a list of those you want to hide.

    1. Once you've deleted the fonts that aren't needed in the list, save the document as a CSV file.
    2. Open the CSV file in notepad and paste the string of font names into the <Name> node within <TTFontInfo>
    3. Set <Hidden> to True or False, this depends on your choice as mentioned above.

    Answer Verified By: Tim Letcher 

  • Gerd,

    I don't know what the difference is between them.  However, this is the second customer to supply me with fonts in this type of naming convention.

    The first customer gave me all variations on Engineering*.ttf.  That was only eight fonts, so no big deal; I just wrote them all out.  The second customer gave me the variations I described above, but this time there were 22 different fonts in that naming convention.  I invested a bit of time in getting a wildcard to work, but I was unsuccessful.  In defeat, I wrote them all out again.

    I assume wildcards work in this file and that I'm just getting something wrong with the syntax.

  • Barry,

    I like this idea a lot, especially if wildcards are not possible.

    I only dabble in PowerShell; clearly, you are on a whole other level.

    I am going to take your code and tweak it to my needs but follow the same workflow.  I have never installed the fonts on my PC; they reside in the font folder for that specific customer.  So, I should be able to output a list of files to a text file and then follow the workflow from there.

    This was great insight, and thank you very much for the detailed procedure.

  • I only dabble in PowerShell; clearly, you are on a whole other level.

    Oh I wouldn't go that far, it was actually as a 2nd resort; My initial thought was to use a VBScript:

    Const FONTS = &H14
    Const ForReading = 1
    Const ForWriting = 2
    
    Dim objShell, objFolder, objFolderItem, objFSO, Folder, Font, FontList()
    
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(FONTS)
    Set objFolderItem = objFolder.Self
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set Folder = objFSO.GetFolder(objFolderItem.Path)
    
    i = 0
    For Each Font In Folder.Files
    
        If Right(LCase(Font.Name), 4) = ".ttf" Then
            Select Case i
                Case 0
                    ReDim FontList(i)
                Case Else
                    ReDim Preserve FontList(i)
            End Select
            FontList(i) = Font.Name
            i = i + 1
        End If
    Next
    
    For a = UBound(FontList) - 1 To 0 Step -1
        For j = 0 To a
            If UCase(FontList(j)) > UCase(FontList(j + 1)) Then
                temp = FontList(j + 1)
                FontList(j + 1) = FontList(j)
                FontList(j) = temp
            End If
        Next
    Next
    
    Dim FSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    Set OutputFile = FSO.CreateTextFile("D:\FontList.txt", True)
    'OutputFile.Write (Join(FontList, ","))
    
    For Z = 0 To UBound(FontList)
        OutputFile.WriteLine FontList(Z)
    Next
    
    Set OutputFile = FSO.OpenTextFile("D:\FontList.txt", ForReading)
    strLine = OutputFile.ReadAll
    intlength = Len(strLine)
    strRemainder = Right(strLine, intlength - 1)
        
    If InStr(strLine, ",") = 1 Then
        Set OutputFile = FSO.OpenTextFile("D:\FontList.txt", ForWriting)
        OutputFile.Write strRemainder
    End If
    
    Set objFSO = Nothing
    Set objShell = Nothing
    Set objFolder = Nothing
    Set objFolderItem = Nothing
    Set Folder = Nothing
    Set OutputFile = Nothing

    However this results in output like this:

    462364.ttf
    AGENCYB.TTF
    AGENCYR.TTF
    ALGER.TTF
    ANTQUAB.TTF
    ANTQUABI.TTF
    ANTQUAI.TTF
    arial.ttf
    arialbd.ttf
    arialbi.ttf
    ariali.ttf
    ARIALN.TTF
    ARIALNB.TTF
    ARIALNBI.TTF
    ARIALNI.TTF
    ARIALUNI.TTF
    ariblk.ttf
    ARLRDBD.TTF
    ArtifaktElementMedium.ttf
    ArtifaktElementRegular.ttf
    bahnschrift.ttf
    BASKVILL.TTF
    BAUHS93.TTF

    The script also lists TTF files which aren't visible in MicroStation, but the file name not matching the Full Name of the font was the main reason for switching to Powershell:

    The Powershell output does match the font pulldown however, the only issue is that the Asian fonts prefixed with the @ symbol don't get listed by either script and need to be hand written to have them hidden from view.