I’m trying to get the location point of ceilings, but all I have is Autodesk.Revit.DB.Location. Methods or attributes like Point, ToPoint, Toxyz, etc. don’t work. Any idea?
Kevin_Bell had a similar problem like me now, but he didn’t get a solution:
Here is an abstract of my code:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("System")
from System.Collections.Generic import List
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def roomNumber(room):
return room.Number
allRooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
rooms = sorted(allRooms, key = roomNumber)
test = []
for room in rooms:
levelRoom = room.LevelId
allCeilings = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Ceilings).WhereElementIsNotElementType().ToElements()
for ceiling in allCeilings:
levelCeiling = ceiling.LevelId
if levelRoom == levelCeiling:
ceilingPoint = ceiling.Location
test.append(ceilingPoint)
OUT = test
Right, ceilings are actually not family instances.
Did not think about that before, but for some elements you will not get a location point.
Eg. for walls you get curve only. I think you can get outline/sketch as suggested above and calculate cetroid / average point perhaps?
Or maybe even easier get the bounding box of the object and take it’s centre.
I get an error with your code and i get a null with Miciek’s.
Maybe this is a bug? We can obviously do a work around, but it’s worth reporting if we’re not getting a result we expect. The ceiling has a location, we should be able to get a point out of it.
element = UnwrapElement(IN[0])
bb = element.get_BoundingBox(None)
max = bb.Max
min = bb.Min
centre = min + (max-min)/2
#Assign your output to the OUT variable.
OUT = centre
No, I didn’t, becasue I want to do it only with python (like a challenge). In the meantime my solution has been getting the middle point of the BoundingBox. I don’t love it but It’s enough for me.
So it looks like the ‘location’ of a ceiling is returned as it’s boundary curves… Have a look in the Clockwork Location + node… That’s a bit weird isn’t it?!
It seems to be the same with roofs, so I guess all sketch based elements?! Ok well that’s what it is then…