Hello!
I’ve just started using Revit API in Dynamo. Forgive me if the question is stupid.
I’m trying to filter wall types to get only that ones which occuring in project. Then I’d like to get parameters of those family types.
Until now I did 2 scripts:
First one: I recive the right types, but they’re multiple - so now I’d like to get result like node: List.UniqueItems. How to achieve that with python?
doc = DocumentManager.Instance.CurrentDBDocument
collector = FilteredElementCollector(doc)
walls = collector.OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
output = []
for wall in walls:
x = wall.Document.GetElement(wall.GetTypeId())
output.append(x)
OUT = output
`
Second one: I get list of IDTypes, then I take unique ones by python’s ‘set()’ function, but I don’t understand how to use ID to return Wall Types
doc = DocumentManager.Instance.CurrentDBDocument
collector = FilteredElementCollector(doc)
walls = collector.OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
output = []
for wall in walls:
x = Element.GetTypeId(wall).ToString()
output.append(x)
setlist = set(output)
OUT = setlist
Hi @Rafat.
Are you trying to filter the walltypes from the document or the walltypes which are ACTIVE in the document? Or both?
Converting your list into a set, like setlist = set(mylist) would list the unique items of the list. You’ll need to convert it back to a list to work with it later. Edit: Just like you mention in the second question.
You can use wall = doc.GetElement(ElementId) and then walltype = wall.walltype().
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)
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
uniqueWalls = []
wallTypes = []
for wall in walls:
if wall.WallType.Id in uniqueWalls:
continue
else:
uniqueWalls.append(wall.WallType.Id)
TransactionManager.Instance.TransactionTaskDone()
OUT = [doc.GetElement(x) for x in uniqueWalls]
@CVestesen, @SeanP
Guys thanks a lot! Both solutions really satisfy me, but @CVestesen’s “wall = doc.GetElement(ElementId)” is the simplest way.
Last question, where did you guys learn these stuff? By now I was studying python from Mark Lutz’s “Learning Python” and Revit’s API from Lynda.com. There are few examples and I understand them, but as you see I have still a lot to learn. Can you reccomend some websites, tutorials etc ?
From Lynda and by doing
Think of something that could be smart and try read the Revit API before you start your coding to find out, how it might be solved