HI there, I am making a script that sorts amongst a lot of Family Types and chooses the adequated one based on the case. They annotate families that add details to my view and are placed automatically based on the sizes, etc.
The problem is, every time the project is changed (Someone adds a Family for example) the index order of types change and it brakes the script, as the selected types changes as well.
from witch I figured what I needed to retrieve the Family Types.
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
import System
from System.Collections.Generic import *
# Place your code below this line
doc = doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#Family symbol name to place.
symbName = 'Trail Shiplap Fill'
#create a filtered element collector set to Category OST_Mass and Class FamilySymbol
collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_GenericAnnotation)
collector.OfClass(FamilySymbol)
famtypeitr = collector.GetElementIterator()
#famtypeitr.Reset()
r=None
re=[]
#Search Family Symbols in document.
for item in famtypeitr:
famtypeID = item
if symbName in item.FamilyName:
re.append([item.Family, item.Id, item.FamilyName])
#If the FamilySymbol is the name we are looking for, create a new instance.
OUT = re
I Probably imported more things that I needed but it worked off some sort.
I canât get the family type though.
If I set to return only the âitemâ variable it returns an object that contains the family type but I canât convert it to string or anything.
Hello Guys,
Sorry to wake up the topic a year afterâŚ
I have a question directly linked to this topic.
What if I want to select all the family loaded in the project as a list ? I know there is a node âFamily Typesâ that gives a scrolling menu with them, but I would want them as a list. I would want to select them all automaticaly whitout creating a list one by one âŚ
Tell me if you have any clue !
This python will give you families and family Types. You can remove the line for either the fams or famTypes if you donât want one or the other.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
element = UnwrapElement(IN[0])
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
fams = FilteredElementCollector(doc).OfClass(Family).ToElements()
famTypes = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()
TransactionManager.Instance.TransactionTaskDone()
OUT = fams,famTypes
@SeanP Would you also know how to do the same kind of things but with parameters. I am working on a family (.rfa), And to like to have access to its own parameters (names, values, formula). I have achieved to get the names, but I canât get the value, I got âNullâ each times.
import clr
clr.AddReference(âRevitAPIâ)
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference(âRevitAPIUIâ)
from Autodesk.Revit.UI import *
clr.AddReference(âSystemâ)
from System.Collections.Generic import List
pNames= #list of names of parameters
pS= #similar to param if all parameters are selected, but can be less, depending on the list of names we want
for p in param:
n=p.Definition.Name
pNames.append(n)
pS.append(doc.FamilyManager.get_Parameter(n))
types = doc.FamilyManager.Types #types of the family
famMan = doc.FamilyManager
categ=doc.OwnerFamily.FamilyCategory.Name family category
family TYPES #add âDefaultâ type in families with no types
familytypecount =
familytypecount.append(types.Size)
if familytypecount < 1:
TransactionManager.Instance.EnsureInTransaction(doc)
new_fam=famMan.NewType(âDefaultâ)
TransactionManager.Instance.ForceCloseTransaction()
while(familyTypesItor.MoveNext()): #getcurrentvalue
for n in pNames:
familyParam = famMan.get_Parameter(n)
familyType = familyTypesItor.Current
>param_values.append(familyType.AsString(familyParam))
#TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()
OUT = fams,famTypes,pNames,param_values,familytypecount
Check this revised Python for Family parameters. This is a good start, but isnât going to cover everything youâll probably need.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
run = IN[0]
#Do some action in a Transaction
famTypes = []
pNames = []
pValue = []
types = doc.FamilyManager.Types
params = doc.FamilyManager.Parameters
if run:
TransactionManager.Instance.EnsureInTransaction(doc)
for param in params:
pNames.Add(param.Definition.Name)
for type in types:
famTypes.Add(type)
for param in params:
StoreType = param.StorageType
if StoreType == StorageType.Double:
v = type.AsDouble(param)
elif StoreType == StorageType.Integer:
v = type.AsInteger(param)
elif StoreType == StorageType.String:
v = type.AsString(param)
elif StoreType == StorageType.ElementId:
v = type.AsElementId(param)
pValue.Add(v)
TransactionManager.Instance.TransactionTaskDone()
OUT = famTypes,pNames,pValue
else:
OUT = "Set Run to True"