How can I get the center point of the part of wall which inside the room?

How can I get the center point of the part of wall which inside the room?

ddk0705
Contributor Contributor
1,764 Views
2 Replies
Message 1 of 3

How can I get the center point of the part of wall which inside the room?

ddk0705
Contributor
Contributor

Hello,

I've used this logic to get all walls of a room:

List<Wall> walls = new List<Wall>();
IList<IList<BoundarySegment>> boundaries = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

foreach (IList<BoundarySegment> b in boundaries)
{
    foreach (BoundarySegment s in b)
    {
        Element el = document.GetElement(s.ElementId);
        if (el is Wall)
        {
            Wall wall = el as Wall;
            walls.Add(wall);
        }
    }
}

However, some walls are longer than edge of the room as this photo

error-6.jpg

 

Basically, 1 part is a wall of the Resi Trash - 158 room (blue border).

So, I want to get the 1a part (red border) which has located inside the room and getting the center point of the 1a part.

 

Thanks, 

 

0 Likes
Accepted solutions (1)
1,765 Views
2 Replies
Replies (2)
Message 2 of 3

FAIR59
Advisor
Advisor
Accepted solution

You can use the boundary Curve to find the midpoint on the RoomWall  ( and the direction into the Room ).

List<Tuple<Wall,XYZ,XYZ>> walls = new List<Tuple<Wall,XYZ,XYZ>>(); // Item1 = wall, Item2 = midpoint, Item3 = direction to Room
IList<IList<BoundarySegment>> boundaries = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

foreach (IList<BoundarySegment> b in boundaries)
{
	foreach (BoundarySegment s in b)
	{
		Element el = doc.GetElement(s.ElementId);
		if (el is Wall)
		{
     			Wall wall = el as Wall;
       			Curve cv = s.GetCurve();
       			XYZ mid = cv.Evaluate(0.5,true); // midpoint on BoundaryCurve
       			// XYZ midpointOmWall = (wall.Location as LocationCurve).Curve.Project(mid);
       			XYZ directionToRoom  = cv.ComputeDerivatives(0.5,true).BasisX.CrossProduct(XYZ.BasisZ).Negate().Normalize();
       			walls.Add(new Tuple<Wall,XYZ,XYZ>(wall,mid,directionToRoom));
		}
	}
}
using (Transaction t = new Transaction(doc,"show_midpoints"))
{
	t.Start();
	foreach(var tuple in  walls)
	{
		XYZ midpoint = tuple.Item2;
		try{
doc.Create.NewDetailCurve(doc.ActiveView,Line.CreateBound(midpoint,midpoint+tuple.Item3.Multiply(5)));
		}
		catch{}
	}
	t.Commit();
}

 

Message 3 of 3

ddk0705
Contributor
Contributor

Thanks @FAIR59  I think it's a good solution.

0 Likes