Skip to content

Commit 13eb0e3

Browse files
author
Jeremy Tammik
committed
implemented TagWallsWithAdjacentRooms based on Richard @RPThomas108 Thomas VB.NET code in https://forums.autodesk.com/t5/revit-api-forum/extract-the-names-of-the-rooms-separated-by-a-wall/m-p/10428696
1 parent cc7a591 commit 13eb0e3

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

BuildingCoder/BuildingCoder/CmdRoomWallAdjacency.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,83 @@ namespace BuildingCoder
3535
[Transaction( TransactionMode.ReadOnly )]
3636
class CmdRoomWallAdjacency : IExternalCommand
3737
{
38+
// Originally implemented by Richard @RPThomas108 Thomas in VB.NET in
39+
// https://forums.autodesk.com/t5/revit-api-forum/extract-the-names-of-the-rooms-separated-by-a-wall/m-p/10428696
40+
41+
/// <summary>
42+
/// For all rooms, determine all adjacent walls,
43+
/// create dictionary mapping walls to adjacent rooms,
44+
/// and tag the walls with the adjacent room names.
45+
/// </summary>
46+
void TagWallsWithAdjacentRooms( Document doc )
47+
{
48+
FilteredElementCollector rooms
49+
= new FilteredElementCollector( doc )
50+
.WhereElementIsNotElementType()
51+
.OfCategory( BuiltInCategory.OST_Rooms );
52+
53+
Dictionary<ElementId, List<string>> map_wall_to_rooms
54+
= new Dictionary<ElementId, List<string>>();
55+
56+
SpatialElementBoundaryOptions opts
57+
= new SpatialElementBoundaryOptions();
58+
59+
foreach( Room room in rooms )
60+
{
61+
IList<IList<BoundarySegment>> loops
62+
= room.GetBoundarySegments( opts );
63+
64+
foreach (IList<BoundarySegment> loop in loops )
65+
{
66+
foreach( BoundarySegment seg in loop )
67+
{
68+
ElementId idWall = seg.ElementId;
69+
70+
if( ElementId.InvalidElementId != idWall )
71+
{
72+
if(!map_wall_to_rooms.ContainsKey(idWall))
73+
{
74+
map_wall_to_rooms.Add(
75+
idWall, new List<string>() );
76+
}
77+
78+
string room_name = room.Name;
79+
80+
if(!map_wall_to_rooms[idWall].Contains( room_name ) )
81+
{
82+
map_wall_to_rooms[ idWall ].Add( room_name );
83+
}
84+
}
85+
}
86+
}
87+
}
88+
89+
using( Transaction tx = new Transaction( doc ) )
90+
{
91+
tx.Start( "Add list of adjacent rooms to wall comments" );
92+
93+
Dictionary<ElementId, List<string>>.KeyCollection ids
94+
= map_wall_to_rooms.Keys;
95+
96+
foreach( ElementId id in ids )
97+
{
98+
Element wall = doc.GetElement( id );
99+
100+
Parameter p = wall.get_Parameter(
101+
BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS );
102+
103+
if( null != p )
104+
{
105+
string s = string.Join( " / ",
106+
map_wall_to_rooms[ id ] );
107+
108+
p.Set( s );
109+
}
110+
}
111+
tx.Commit();
112+
}
113+
}
114+
38115
void DetermineAdjacentElementLengthsAndWallAreas(
39116
Room room )
40117
{

BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
// 2021-06-21 2022.0.150.12 added AdjustColumnHeightsUsingReferenceIntersector from https://forums.autodesk.com/t5/revit-api-forum/ray-projection-not-picking-up-beams/m-p/10388868
386386
// 2021-06-29 2022.0.150.13 added SetMaterialAppearanceAssetKeywordProperty
387387
// 2021-07-01 2022.0.150.14 added enhancement by Andrey for quadrilateral to GetPolygonPlane
388+
// 2021-07-05 2022.0.150.15 implemented TagWallsWithAdjacentRooms based on Richard @RPThomas108 Thomas VB.NET code in https://forums.autodesk.com/t5/revit-api-forum/extract-the-names-of-the-rooms-separated-by-a-wall/m-p/10428696
388389
//
389-
[assembly: AssemblyVersion( "2022.0.150.14" )]
390-
[assembly: AssemblyFileVersion( "2022.0.150.14" )]
390+
[assembly: AssemblyVersion( "2022.0.150.15" )]
391+
[assembly: AssemblyFileVersion( "2022.0.150.15" )]

0 commit comments

Comments
 (0)