Just curious -- is there a reason you can't use the BOUNDARY command or the HATCH command?
Just finding the closest line in a given direction does not necessarily guarantee that you'll trace a room's walls. Consider a room shaped like an "L" or like a "U", or any room with recesses in the walls. Its easy to have walls that can't be be seen from a selection point.
I don't program in .NET, but I have been pondering this problem for a while. There are a number of ways to get an inside boundary. A few links are:
http://www.theswamp.org/index.php?topic=10371.0http://www.theswamp.org/index.php?topic=26986.0http://www.theswamp.org/index.php?topic=24000.0A few things to look out for are gaps (lines that appear to touch do not always do so due to sloppy drafting, conversions from other systems, or rounding errors) and very small changes in the surface (for example, a wall with a "picture frame" surface where the surface bumps out 1/2" -- it can be hard to pick up very small changes to the surfaces). I'm toying with a lisp routine which will draw an arbitrary construction from a selected point to find a starting point on the boundary, then trace around the space. I'm using the same approach as in fastsel.lsp (one of the express tools), which is to use getss with the fence option. Fastsel gets selection sets on the base entity, a small offset to the right, and a small offset to the left. Curves are done in segments. My code looks at a fence offset toward the inside of the room. If nothing is found it looks at a small crossing window at the far end of the base entity, which will find end-to-end line segments and intersections which turn away from the inside of the room. If still nothing it looks at a fence offset to the outside to catch situations where the first line overshoots the intersection.