I’m trying to create a tool to check if our MEPT elements are on walls. They are not hosted. I’m new to python, the API, and coding in general. I’ve made a few python nodes in Dynamo but that is it.
From the code below you can probably see that I’m poking around in the dark, trying to find something that would be useful. At first I assumed that I could get the solids of both the walls and elements and see if they intersect but have had issues trying to even get the solid. I also can’t seem to find anything I could use to check if they intersect.
I’ve also started looking into the Location class and HostObjectUtils for the walls. It seems like I’m able to get to a certain point with obtaining information like the curve or point or face, but then stumble on trying to find some method on how to determine how they related to each other.
I’m not asking for the code but if anyone has done something similar and would be willing to point to the best classes and methods I could try creating it myself. Thanks for any help.
# Check if on wall
# Import libraries
from pyrevit import DB, revit, script, forms
from Autodesk.Revit.DB import *
#FilteredElementCollector,
#RevitLinkInstance,
#GeometryInstance)
from System.Collections.Generic import List
# Current document
doc = __revit__.ActiveUIDocument.Document
################################################################################
# Linked documents
link_instances = FilteredElementCollector(doc) \
.OfClass(RevitLinkInstance)\
.ToElements()
link_docs = []
for l in link_instances:
if l.GetLinkDocument() != None:
l_doc = l.GetLinkDocument()
if l_doc:
link_docs.append(l_doc)
else:
pass
else:
pass
################################################################################
# Get items for comparing
getFixtures = FilteredElementCollector(doc).\
OfCategory(DB.BuiltInCategory.OST_ElectricalFixtures).\
WhereElementIsNotElementType().\
ToElements()
getWalls = []
for l in link_docs:
lWalls = FilteredElementCollector(l).\
OfCategory(DB.BuiltInCategory.OST_Walls).\
WhereElementIsNotElementType().\
ToElements()
for w in lWalls:
getWalls.append(w)
################################################################################
# Get Element location info
fLocation = []
for f in getFixtures:
fLocation.append(f.Location.Point)
print(fLocation)
print("____________________________________________________________________")
wLocation = []
for w in getWalls:
wLocation.append(w.Location.Curve)
print(wLocation)
gWalls = []
for w in getWalls:
extSide = HostObjectUtils.GetSideFaces(w,ShellLayerType.Exterior)
for e in extSide:
extface = w.GetGeometryObjectFromReference(e)
if extface == None:
continue
else:
gWalls.append(extface)
print(extface)
#print(getFixtures)
#print(getWalls)
################################################################################
# Get geometry
# fGeometry = []
# for f in getFixtures:
# fGeometry.append(f.get_Geometry(Options()))
# wGeometry = []
# for w in getWalls:
# wGeometry.append(w.get_Geometry(Options()))
# fTest = []
# for f in getFixtures:
# fGeo = f.get_Geometry(Options())
# fgEnum = fGeo.GetEnumerator()
# next = fgEnum.MoveNext()
# geoInst = fgEnum.Current
# instGeo = geoInst.GetInstanceGeometry()
# fTest.append(instGeo)
# fBox = []
# for f in fGeometry:
# fBox.append(f.GetBoundingBox)
#print(fBox)
#print(geoInst.__getattribute__)
#print(dir(geoInst))
#print(fTest)
# print("____________________________________________________________________")
# print(fGeometry)
# print("____________________________________________________________________")
# print(wGeometry)
# test = fGeometry[0].GetEnumerator()
# print("____________________________________________________________________")
# print(test)
# test2 = test.Current
# print("____________________________________________________________________")
# print(test2)
################################################################################
# Compare lists