Hi all,
I’m currently working on a script that changes the familysymbol name. but some way i can’t get this one to work.
Objective/workflow: in our company we are using a base parametric family(called: Betonplint - parametrisch), which is loaded in to a adaptive family, which is loaded in to a secondary adaptive main family. so we have a dynamo script that generates and saves these families with dimensions from an excel sheet. and later on this generated families will be loaded in to a project and with an other dynamo script we place these adaptive families in ‘the world’ with coordinates. when that model i generated we are using ‘Navisworks Manage’ to share our model with our client. but due the fact we are using 1 base family, all families wil return with there base name in Navisworks manage. See screenshot below:
But see this picture how we want to present the navisworks tree:
i achieved this by renaming the family with this method and by renaming it’s type with this method.
But as we have already a python script that generates these families i wan’t to integrate this. Renaming the family works(green marked) but renaming it’s type(red marked) not. see the pictures below from the script/ input-output and the result in the projectbrowser in revit.
this is the python script i use for generating, renaming and saving the families.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from Autodesk.Revit.DB import FilteredElementCollector, Family
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
doc = DocumentManager.Instance.CurrentDBDocument
name = IN[0]
compact = IN[1]
newcentral = IN[2]
isworkshared = IN[3]
elmts = IN[4]
parmNam = IN[5]
val = IN[6]
searcha = IN[7]
renamea = IN[8]
for i in range(len(name)):
for j in range(len(val[i])):
Revit.Elements.Element.SetParameterByName(elmts[0], parmNam[i][j], val[i][j])
#TransactionManager.Instance.ForceCloseTransaction()
search=searcha[i]
rename=renamea[0][i]#[i]
type_name = []
collector = FilteredElementCollector(doc).OfClass(Family)
TransactionManager.Instance.EnsureInTransaction(doc)
for element in collector.ToElements():
for idx, searched in enumerate(search):
if searched == element.Name:
element.Name = rename[idx]
type_name.append(element.Name)
TransactionManager.Instance.ForceCloseTransaction()
searchb=searcha[i]
renameb=renamea[0][i]#[i]
type_namea = []
type_namecheck = []
familytypes = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()
TransactionManager.Instance.EnsureInTransaction(doc)
for typ in familytypes:
typename = typ.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
typename_object = typ.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM)
type_namea.append(typename)
if searchb[0] == typename:
type_namecheck.append("gevonden")
#typeName = typename_object.LookupParameter(searchb[0]).Set(renameb[0])
#typeName = typename.Name(BuiltInParameter.SYMBOL_NAME_PARAM).Set(renameb)
TransactionManager.Instance.ForceCloseTransaction()
if doc.IsFamilyDocument:
name[i] += '.rfa'
else:
name[i] += '.rvt'
opt = SaveAsOptions()
opt.OverwriteExistingFile = True
opt.Compact = compact
if isworkshared and newcentral:
wsopt = WorksharingSaveAsOptions()
wsopt.ClearTransmitted = True
wsopt.SaveAsCentral = True
opt.SetWorksharingOptions(wsopt)
try:
doc.SaveAs(name[i], opt)
OUT = 'ALLE ELEMENTEN ZIJN GEGENEREERD',type_name,searcha,search,renamea,rename,type_namea,familytypes,searchb,renameb,type_namecheck
except:
try:
wsopt.ClearTransmitted = False
opt.SetWorksharingOptions(wsopt)
doc.SaveAs(name[i], opt)
OUT = 'not done',type_name,searcha,search,renamea,rename,type_namea,familytypes,searchb,renameb,type_namecheck
except:
OUT = 'not done',type_name,searcha,search,renamea,rename,type_namea,familytypes,searchb,renameb,type_namecheck
The question:
what line of code do i need after the “if searchb[0] == typename:” to set the name ?
as you can see i tried two different options but both are giving error’s.
PS: i’m working with revit 2021.
Gr Edward