Dear Feng Wang,
Thank you for the updated code.
I cleaned it up a little bit more and added it to The Building Coder samples:
https://github.com/jeremytammik/the_building_coder_samples
It lives in the new external command CmdExteriorWalls:
https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/C...
The main modification I made was to use the existing walls' bounding boxes to determine the maximum model extents.
Retrieving the bounding box of an element is an extremely fast and efficient operation.
This approach also saves the need for complex handling of the wall location lines.
The Building Coder samples Util class even already includes an extension method `ExpandToContain` that expands a bounding box to contain another one.
Using that, I implemented the method GetWallBoundingBoxAroundAllWalls like this:
/// <summary>
/// Return a bounding box around all the
/// walls in the entire model; for just a
/// building, or several buildings, this is
/// obviously equal to the model extents.
/// </summary>
static BoundingBoxXYZ GetBoundingBoxAroundAllWalls(
Document doc,
View view = null )
{
// Default constructor creates cube from -100 to 100;
// maybe too big, but who cares?
BoundingBoxXYZ bb = new BoundingBoxXYZ();
FilteredElementCollector walls
= new FilteredElementCollector( doc )
.OfClass( typeof( Wall ) );
foreach( Wall wall in walls )
{
bb.ExpandToContain(
wall.get_BoundingBox(
view ) );
}
return bb;
}
For the rest of the updated code, please check out the GitHub repository.
You can also see the modifications I made to your code step by step by looking at individual commits in the list of changes between version 2019.0.140.0 and 2019.0.140.1:
https://github.com/jeremytammik/the_building_coder_samples/compare/2019.0.140.0...2019.0.141.0
Cheers,
Jeremy