Changing "Text Font" In Families

As a standard, my office wants to use a different font vs. the default Arial text font in annotation families. I began to open each individual annotation family, select edit type and changing the Text Font from Arial to a font of their liking and then saving the file and deleting the backup file. This seems a bit tedious. My understanding is that Dynamo can help with these tedious tasks. I am very new to Dynamo and interested in learning how to create these dynamo scripts. I’ve seen a topic here and began to create a script. When I do a search for some of these nodes, it seems that I am not finding the proper nodes.

1 Like

@kim.candelario ,

hmmm… its doing nothing in the family :confused:

Hello,
try this

set font in family

import sys
import clr
import System
from System.Collections.Generic import List
clr.AddReference('System.Drawing')
from System.Drawing import Text as DText
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

fontName_to_set = IN[0]

allFontName = [fa.Name for fa in DText.InstalledFontCollection().Families]
if fontName_to_set not in allFontName:
    raise Exception("Error", "This text Font is not available")

remove_subClass = System.Predicate[System.Object](lambda x : x.GetType() == clr.GetClrType(DB.TextElementType))
lst_textNoteType = List[DB.Element](FilteredElementCollector(doc).OfClass(DB.TextElementType).WhereElementIsElementType().ToElements()).FindAll(remove_subClass)

TransactionManager.Instance.EnsureInTransaction(doc)
for textNoteType in lst_textNoteType:
    para_noteFont = textNoteType.get_Parameter(BuiltInParameter.TEXT_FONT)
    para_noteFont.Set(fontName_to_set)

TransactionManager.Instance.TransactionTaskDone()

OUT = lst_textNoteType
2 Likes

@c.poupin ,

i am in a family enviroment, but what should happen?
2022-07-15_11h42_44
2022-07-15_11h42_50

The previous example works only for annotation families (for labels), here a version should be works with TexteNotes too

import sys
import clr
import System
from System.Collections.Generic import List
clr.AddReference('System.Drawing')
from System.Drawing import Text as DText
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

fontName_to_set = IN[0]

allFontName = [fa.Name for fa in DText.InstalledFontCollection().Families]
if fontName_to_set not in allFontName:
    raise Exception("Error", "This text Font is not available")

lst_textNoteType = FilteredElementCollector(doc).OfClass(DB.TextElementType).WhereElementIsElementType()

TransactionManager.Instance.EnsureInTransaction(doc)
for textNoteType in lst_textNoteType:
    para_noteFont = textNoteType.get_Parameter(BuiltInParameter.TEXT_FONT)
    para_noteFont.Set(fontName_to_set)

TransactionManager.Instance.TransactionTaskDone()

OUT = lst_textNoteType
3 Likes