Hello everybody,
I try to change the font size in an invited family. Additionally scale linen and the like. I have already found some entries in the forum, for example:
import clr
# Import DocumentManager and TransactionManager...
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument
# Import RevitAPI...
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
############## Classes ###############
# Define FamilyLoadOptions...
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self,familyInUse,overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, familySrc, overwriteParameterValues):
familySrc = FamilySource.Family
overwriteParameterValues = True
return True
############# Definitions ##############
# Open and search family doc for suitable Element Types to set font...
def UpdateTextFontInFamily(doc, f):
# Must force close all open transactions to open family...
TransactionManager.Instance.ForceCloseTransaction()
try:
arr = []
outList.append(f.Name)
# The Parameter we are looking for...
bip = BuiltInParameter.TEXT_FONT
# Open Family Document...
fDoc = doc.EditFamily(f)
ElementTypes = FilteredElementCollector(fDoc).OfClass(ElementType).ToElements()
# Wrap in a Transaction...
TransactionManager.Instance.EnsureInTransaction(fDoc)
# Search all ElementTypes for Parameter and set Text Font if found...
for i in ElementTypes:
tArr = []
try:
p = i.get_Parameter(bip)
p.Set(font)
tArr.append(i.FamilyName)
tArr.append(i.get_Parameter(bip).AsString())
arr.append(tArr)
# If parameter was not found in this ElementType then move on to next ElementType...
except:
continue
outList.append(arr)
# Must Force Close Transaction to close FamilyDoc...
TransactionManager.Instance.ForceCloseTransaction()
# Load Family back into project and Close Family Document...
fDoc.LoadFamily(doc, FamilyOption())
fDoc.Close(False)
except Exception,e:
outList.append(f.Name + " Failed:-\n" + e.message)
# Convert single object to list if not list already
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
############## Inputs ###############
run = tolist(IN[0])[0]
fams = tolist(UnwrapElement(IN[1]))
font = tolist(IN[2])[0]
############## Outputs ###############
outList = []
############## Main ###############
if run:
for f in fams:
try:
# Skip InPlace Families...
if not f.IsInPlace:
UpdateTextFontInFamily(doc,f)
except Exception,e:
outList.append("Failed:-\n" + e.message)
# Refresh the Active View to see changes immediately...
uidoc.RefreshActiveView()
OUT = outList
else:
OUT = "Please set Run to True"
Youtube - Change Font In Families With Dynamo - Dinamo
https://danimosite.wordpress.com/2017/09/16/changing-fonts-in-families-programmatically/
Can this script be adapted to my question? Unfortunately I failed in my attempts.
To opening families via document path, is not an option in this case.
Thank you!