(defun c:j( / ent pt ents i n npt item lstNew)
  (setq ent(entsel))
  (setq pt(cadr ent))
  (setq ents(entget(car ent)))
  (setq i 0
  npt 0
  n(length ents)) 
  (while(< i n)
   (setq item(nth i ents))
   (cond
   ( (= npt 0)
   (if(=(car item) 10)(setq npt(1+ npt)))
   (setq lstNew(append lstNew(list item)))
   )
   ( (= npt 1)
   (if(and(=(car item) 10)
  (equal(angle(cdr(nth (- i 4) ents)) pt)
   (angle pt(cdr item)) 0.1))
  (progn
   (setq lstNew(append lstNew(list(cons 10 pt) '(40 . 0) '(41 . 0) '(42 . 0) item(nth(1+ i) ents)(nth(+ i 2) ents))))
   (setq i(+ i 3))
   (setq npt(1+ npt))
   )
  (setq lstNew(append lstNew(list item)))
   ) 
   
   )
   ( (= npt 2)
   (setq lstNew(append lstNew(list item)))
   )
   );cond
   (setq i(1+ i))
   );repeat
  (entmod lstNew)
  (princ)
) 