I try changes parameter Text Font from elements into families, but i have a trouble, please help me find solution! Script find elements but can’t changes the values because method Set is not available.
This is my code and screenshot:
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
NameOfType = IN[0]
errorReport = None
output = None
try:
def setWhatYouNeed(d, s):
TransactionManager.Instance.ForceCloseTransaction()
familyDoc = doc.EditFamily(s)
TextNotesType = FilteredElementCollector(familyDoc).OfClass(TextNoteType).ToElements()
DimensionsType = FilteredElementCollector(familyDoc).OfClass(DimensionType).ToElements()
TransactionManager.Instance.EnsureInTransaction(familyDoc)
for list in [DimensionsType,TextNotesType]:
for element in list:
element.LookupParameter("Text Font").Set(IN[0])
TransactionManager.Instance.TransactionTaskDone()
for symbol in IN[1]:
setWhatYouNeed(UnwrapElement(symbol).Symbol.Family.Document, UnwrapElement(symbol).Symbol.Family)
except:
import traceback
errorReport = traceback.format_exc()
if errorReport == None:
OUT = output
else:
OUT = errorReport
It’s not saying set is not available, it is saying that you are passing in nulls and that’s is why set is not available. Have you debugged by outputting just the lists of dimension/text note types? You could add a small change to test if the object is null before trying to get and set it’s parameters.
I append the elements in the list and this list consist different elements which i should changes. But when i try changes this elements I get this error.
Thank you for the your reply, but it’s not the same problem.
I found it topic before - but in this case Konord changes the parameter of family. I want changes the parameter of elements which located in the family.
Perhaps this may help a little on how to achieve this. I have made two nodes, one to get the Text Node Types in the current doc, the other to set the font. Modify as needed…
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
tnTypes = FilteredElementCollector(doc).OfClass(TextNoteType).ToElements()
p = BuiltInParameter.ALL_MODEL_TYPE_NAME
names = [tnt.get_Parameter(p).AsString() for tnt in tnTypes]
OUT = tnTypes, names
TextNoteType.SetFont (Py)
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
# TextNoteTypes to update...
tnTypes = tolist(UnwrapElement(IN[0]))
# Only accepting one text fornt for now
fontName = tolist(IN[1])[0]
outList = []
p = BuiltInParameter.TEXT_FONT
TransactionManager.Instance.EnsureInTransaction(doc)
for t in tnTypes:
try:
textFont = t.get_Parameter(p)
textFont.Set(fontName)
outList.append("Success")
except Exception, e:
outList.append("Failed to update:- \n" + e.message)
TransactionManager.Instance.TransactionTaskDone()
OUT = outList
Daniel_Woodcock1, Thank you for your reply, but it’s not a solve the problem. I have solution for changes value of parameters (Text Font) in the project. This is my code for this goals:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
doc = DocumentManager.Instance.CurrentDBDocument
ElementTypes = FilteredElementCollector(doc).OfClass(ElementType).ToElements()
result = []
TransactionManager.Instance.EnsureInTransaction(doc)
for i in ElementTypes:
for j in i.Parameters:
if j.Definition.Name == "Text Font":
i.LookupParameter("Text Font").Set(IN[0])
result.append(i)
TransactionManager.Instance.TransactionTaskDone()
OUT = result
But when I try make the same into different families in the project I can’t do it.
And now i have the next problem: I changed values into families but I can’t reload families with this changes in the project.
If someone can show when I make a mistake - please let me know!
Now my code looks like this:
import clr
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self,familyInUse,overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
overwriteParameterValues = True
return True
NameOfType = IN[0]
result = []
def setWhatYouNeed(d, s):
TransactionManager.Instance.ForceCloseTransaction()
familyDoc = doc.EditFamily(s)
# owner = familyDoc.OwnerFamily
ElementTypes = FilteredElementCollector(d).OfClass(ElementType).ToElements()
TransactionManager.Instance.EnsureInTransaction(d)
for i in ElementTypes:
for j in i.Parameters:
if j.Definition.Name == "Text Font":
i.LookupParameter("Text Font").Set(IN[0])
result.append(i.LookupParameter("Text Font").AsString())
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()
familyDoc.LoadFamily(doc, FamilyOption())
familyDoc.Close(False)
for symbol in IN[1]:
setWhatYouNeed(UnwrapElement(symbol).Symbol.Family.Document, UnwrapElement(symbol).Symbol.Family)
OUT = result
I have only filtered tags in this graph for text font update, but you can filter what you need I think. ChangeTextFontInAllFamilies.dyn (26.4 KB)
One thing I noticed is that I also wasn’t seeing any text updated. But I was specifically looking at tags and you need to get the TypeId for the annotation element family. I have also changed your code a bit (not much) with some exception handling, list handling and now it takes families directly rather than elements.
Here is a slightly cleaner version of the above sticking to mostly what is in the box.
Slight cleanup on the code also and using the get_Parameter(BuiltInParameter.TEXT_FONT) like my earlier post rather than a string search as @til.shviger flagged up in a separate post will cause errors in different languages should you want to distribute it.
Output data is a little more descriptive too, so you can see what ElementTypes were updated in the family for each family. Run input added if you want to keep it and a doc.refresh to tie it all off.
Hi all, I wanted to say thanks for this. In my case there were a couple of families that did not change font, mostly Annotation Symbols (Level Heads, Grid Heads, Etc). So here’s how I did it, perhaps there are better ways, just wanted to help others in return. I used the springs collector to search for the family types that needed a font change, in my case most of them were Grid Heads, Level Heads, Section Heads, so I used the word Heads to select those families and it worked great.