Room bounding wall elements are not identified

Room bounding wall elements are not identified

Anonymous
Not applicable
845 Views
6 Replies
Message 1 of 7

Room bounding wall elements are not identified

Anonymous
Not applicable

The macro pasted below is meant to select the wall/floor/ceiling that corresponds to each face of the Solid object obtained from a room. (I need the face as well as its host element for the application I am working on). It occasionally fails to find walls that correspond to specific faces, as seen in the image (Revit 2020 file attached). I am unable to figure out how to prevent this.  

 

More specifically spatialElementBoundarySubfaceList.Count is zero unexpectedly for these walls. 

SelectRoomBoundingElems.png

 

		public void SelectRoomBoundingElements()
		{
			UIDocument uidoc = this.ActiveUIDocument;
			Document doc = uidoc.Document;	
			
			FilteredElementCollector collector = new FilteredElementCollector(doc);
            ICollection<Autodesk.Revit.DB.Element> collection = collector.OfClass(typeof(SpatialElement)).ToElements();
            
            var boundingElemIds = new List<ElementId>();
            
            foreach (Autodesk.Revit.DB.Element roomElem in collection)
            {
            	
            	Autodesk.Revit.DB.Architecture.Room room = roomElem as Autodesk.Revit.DB.Architecture.Room;
            	
                if (null == room)
                	continue;
                
            	SpatialElementGeometryCalculator calculator = new SpatialElementGeometryCalculator(doc);

            	SpatialElementGeometryResults results = calculator.CalculateSpatialElementGeometry(room);

            	Solid spaceSolid = results.GetGeometry();
            	
            	
	            foreach (Face face in spaceSolid.Faces)
	            {
                	IList<SpatialElementBoundarySubface> spatialElementBoundarySubfaceList = results.GetBoundaryFaceInfo(face);

                	if (spatialElementBoundarySubfaceList.Count == 0)
                		continue;

                	boundingElemIds.Add(spatialElementBoundarySubfaceList[0].SpatialBoundaryElement.HostElementId);
	            }
	            
	            uidoc.Selection.SetElementIds(boundingElemIds);
            }
            
		}

 

 

0 Likes
Accepted solutions (1)
846 Views
6 Replies
Replies (6)
Message 2 of 7

jeremy_tammik
Alumni
Alumni

You never select anything but the first entry in the sub-face list, spatialElementBoundarySubfaceList[0].

 

Have you checked whether more entries are available?

 

Maybe those are the ones you are missing?

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi Jeremy, 
Thanks for your reply. spatialElementBoundarySubfaceList is an empty list for the faces in question, I checked by running the debugger. 

0 Likes
Message 4 of 7

RPTHOMAS108
Mentor
Mentor
Accepted solution

This appears to be due to unclean wall modelling i.e. where walls don't join as one it is either because the end points don't coincide (overlap) or they are not in the same plane. Probably it struggles where lines are almost in the same plane but not quite.

 

When you correct these errors the macro works ok (see attached).

 

You probably need a different approach if your starting point is this kind of Revit modelling standard. Although would be interested to see if dissimilar wall type within a wall line causes the same issue. When walls are not joined correctly along a straight there are usually these warnings to look for:

 

Capture210321.PNG

Often it is ignored as applies to many irrelevant elements (detail lines etc.) but when applicable to walls it is quite important.

Quick to fixQuick to fix

 

Message 5 of 7

Anonymous
Not applicable

Hi @RPTHOMAS108 ,
Thanks a lot for your solution! Yes your suspicions are correct, faces where wall thickness change due to dissimilar types on the same line are not recognized as belonging to any wall element. 

0 Likes
Message 6 of 7

Anonymous
Not applicable

A follow-up question, is there any inbuilt functions in the Revit API to fix these warnings? For example, snapping to the axis if there is 'slightly off axis' warning? (This seems difficult to do with a custom macro without breaking connectivity with something else. Rotating a wall to snap to axis might just push the same problem to the next wall that it is connected to)

0 Likes
Message 7 of 7

RPTHOMAS108
Mentor
Mentor

If you form a line between the endpoints of your target alignment you can use Curve.Project for each intermediate wall end point to establishing location along that line to where point should be (to conform with curve). The difficulty is you have to move the end a distance greater than short curve tolerance. So often you would:

Measure distance of move

If distance is less than short curve tolerance move it away (by amount slightly greater than short curve tolerance), then move it back onto the target point.

If distance is greater than short curve tolerance you can move it directly onto the target point.