List of Fonts Installed on Computer


#1

Some background: We have some clients with specific standards that vary from our office standard, regarding fonts to be used for text/text-related items. I am hoping to automate the conversion using Dynamo, and, thanks to the assistance of some threads here, such as this one. I have that worked out, but in testing I noticed that if I supply a “new” font name that does not exist on the computer, instead of throwing an error, it still proceeds with the change, resulting in a Text Font parameter with a blank value. The font on placed items appears to revert to Arial, but that blank property value bothers me, even though Arial is our office standard. It feels like a corruption waiting for the best time to bring a model down.

To ease my paranoia, I thought it would be great if I could generate a list of all of the fonts installed on a computer, compare the user input value against that list, and either prevent the change from being made or use a default font (probably Arial) instead of the one the user typed. I found some Python code online here. I tested the code in PyCharm, and it worked.

Using Dynamo 1-3-2, I created a Python Script node and pasted in that same code, after first importing sys and appending the Iron Python 2.7 library to the sys.path, as I had learned that ctypes was a built-in module there in Jeremy Graham’s LinkedIn Learning class, Dynamo for Revit: Python Scripting (2017). I removed the print statement and assigned fontlist as the output of the Python Script node. Somewhat to my surprise, it worked, and generated a list of font names.


image

However, I then found if I closed the Dynamo graph with that Python Script node and reopened it, that the code failed, and I got the following error message:
image
I am not certain why getting a WinFunctionType when you expect a WinFunctionType is an error, but then I do not really understand the code that generates the list of font names. What I have found is that if I edit the script on line 11
from ctypes import wintypes
change it to
from XXXctypes import wintypes
and then save changes and rerun the graph, the error changes to this
image
Then, I can edit the node again, remove the “XXX” from in front of ctypes on line 11, save the changes, and run the graph and it works.

That is clearly not something I want users to have to do. I would much rather provide a warning in 72 point red text telling them to carefully enter the new font name, checking three times that it is installed on the machine and that the name is correctly entered. But I would like to be able to provide a check on the font name entered, and since the code works sometimes, I would appreciate any insight anyone can provide as to why it fails other times, and what, if anything, can be done to get it to work all of the time.

I am attaching the DYN file containing the Installed Fonts - Python Script node (only node in the file), from Dynamo 1-3-2. I have also opened a copy of this file in Dynamo 2-0-2, and the behavior is the same. Thanks for any help you can provide. I am also open to suggestions on other means to achieve the same result - being able to determine if a user entered string represents the name of an installed font file.

David Koch

1-3-2_FontList.dyn (2.4 KB)