I know this is a very basic question, but I cant find an appropriate answer anywhere (this maybe a result of my non understanding of the theory behind it).
I have filtered out all of the instances of walls in a given project.
I then want to loop over those walls and find both the type name and the family name.
I have tried to use .WallTypes and .GetType, but they return Autodesk.Revit.DB.Wal, but i would like the literal name.-
Do you have all the correct Imports as shown below?
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])
WallTypes = []
names = []
FamilyNames = []
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
wallTypes = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType()
for wallType in wallTypes.ToElements():
WallTypes.append(wallType)
names.append(Element.Name.__get__(wallType))
FamilyNames.append(ElementType.FamilyName.__get__(wallType))
TransactionManager.Instance.TransactionTaskDone()
OUT = WallTypes,names,FamilyNames
In this example, I am just collecting all the wall types in the project. If you are wanting to collect all walls (instances) then yes that is a little different for the Collector. Is that what you are wanting?
I am collecting all of the wall instances in the project, then when I have them (which I do) I then want to just find out what the name of the type is and what the name of the family is (eg. basic wall or curtain wall etc).
I believe you did not add the imports as @SeanP mentioned.
I’d have a look into the Revit Lookup tool to search your specific parameters within Revit. Play around with it to get a better understanding of the API.
Looks OK at face value, if you’re hitting RAM issues it’s probably too many elements for Dynamo to deal with. Test it on a small model to see if it works in principle, then if it does then it’s the element count which is the limitation. Aside from breaking up the workflow into stages it will probably be difficult to process a large outcome without addins/C#.
This is the leanest it can be written short of oneliners and importing specific objects:
# Boilerplate text
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument
# Do some action in a Transaction
famsymbs = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()
nameList = []
for i in famsymbs:
fn = i.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()
nameList.append(fn)
# Preparing output to Dynamo
OUT = nameList
You can also try passing the element collector to Dynamo and feeding it into the Element.Name node. Not sure how much faster that is though.