The code needs to be slightly adapted for a list of rooms as input instead of a single room. I’ll gpost the complete solution if you get stuck.
1 Like
my next problem is that im trying to place my module but it wont rotate the right way. do you guys have any idea on how to fix that? the back of the module needs to face the wall we found between both rooms. right now this is what i get when i place the modules. the red circles are the modules that are placed right
Here is an example of how to get the angle from XYZ.BasisY in radians (You can also use XYZ.BasisX, depending on the orientation of your family.)
import clr
import sys
import System
#
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def find_wall_by_adjacent_room(room, adajcent_room_name):
#
calculator = SpatialElementGeometryCalculator(doc)
#
if calculator.CanCalculateGeometry(room):
results = calculator.CalculateSpatialElementGeometry(room)
roomSolid = results.GetGeometry()
for face in roomSolid.Faces:
for subface_info in results.GetBoundaryFaceInfo(face):
if subface_info.SubfaceType == SubfaceType.Side:
lnkelemId = subface_info.SpatialBoundaryElement
elem = doc.GetElement(lnkelemId.HostElementId )
if isinstance(elem, Wall):
subface = subface_info.GetSubface()
bbxuv = subface.GetBoundingBox()
face_normal = subface.ComputeNormal((bbxuv.Min + bbxuv.Max) / 2)
# compute the angle to XYZ.BasisZ
factor = 1 if face_normal.CrossProduct(XYZ.BasisY).Z > 0.01 else -1
angle = face_normal.AngleTo(XYZ.BasisY) * factor
#
# set the length of the vector
face_normal = face_normal * elem.Width * 1.1 # 1.1 --> margin offset vector
midpt = subface.Evaluate((bbxuv.Min + bbxuv.Max) / 2)
project_pt = midpt + face_normal
ajacent_room = doc.GetRoomAtPoint(project_pt)
if ajacent_room is not None and adajcent_room_name in ajacent_room.Name :
print(angle)
return elem
input_room = UnwrapElement(IN[0])
adajcent_room_name = IN[1]
OUT = find_wall_by_adjacent_room(input_room, adajcent_room_name)

