Yes, EndARef and EndBRef should be where it couldn't identify a node at the end of the polyline I think, it should be selecting them - let me have a look and a think. There were a couple of lines it didn't like as well, will see what they are doing too
EDIT:
Just checked what I thought. to get the node blocks assigned to the ends of each polyline there is a 'fuzz factor' - so that if they are not exactly equal it will find them anyway - I've set this at 0.01, a couple of the nodes are slightly further away from the line ends, so we can increase the fuzz factor. Depending on the minimum pipe length you -could- increase this quite a lot, I'll go 10x larger
Find and replace:
(equal EndA (cdr (assoc 10 (entget BLEnt))) 0.01 ) ; compare the 2 include fuzz factor
change to
(equal EndA (cdr (assoc 10 (entget BLEnt))) 0.1 ) ; compare the 2 include fuzz factor
and the same looking for (equal EndB ..... )