@adaptacad wrote:
.... to indicate the direction and quantity.
so the understanding is better are basically these senses
return '((1 "N") (2 "E") (1 "NE") (1 "O"))
....

But that should be determining angles not in relation to absolute compass directions, but as directions relative to the rotation of the Block, if I understand the image in Message 1 correctly.
I see a problem with the nature of the Polylines. The long horizontal above is one Polyline all the way across [though at least it has a vertex in the middle], so the same Polyline extends in more than one direction from the Block, and that is in its drawn direction on one side but in the opposite direction on the other side. Likewise for the two diagonals, which are a single Polyline. In other situations in the sample drawing, there are L-shaped 2-segment ones, and some that extend in only one direction with a single segment. It would be difficult to find an approach that can account for all those possibilities, and would be much easier if all of them were separate ones, with none continuing through at the middle. I think @doaiena 's suggestion assumes they are separate, since it looks at each Polyline only once, not one segment at a time. That can give only one result per Polyline, but you are looking for two results from many of your Polylines.
But even if they were all separate pieces, that approach could, I think, give opposite-direction results in some cases if any are drawn in the inward direction, depending on the specific position of their inward end relative to the reference point or the Block. If the nearest point of one drawn inward is at the downstream end, there will be no next parameter value, so the angle measurement will fail. If the nearest point on it isn't at the very end, whether User-selected or based on the Block's insertion point, then the rounded-down parameter will be at the outward end, and the angle will be measured in the opposite direction from the one intended. This would be the case, for example, in the upper non-orthogonal situation if its lower-right Polyline were drawn from the outside in, instead of the way it is, and if the reference point is the Block insertion point. @doaiena's suggestion asks the User for the reference point, but it would make sense to me to have that taken from the Block, since the Block needs to be selected anyway, if the angle determinations are to be relative to its rotation angle.
Also, are they always Polylines, or might they sometimes be Lines, or something else?
Kent Cooper, AIA