Thank you guys but it's still not working..QAFLAGS was set to zero.
Anyway, I studied some examples and made changes to the routine.
Now it works. Not sure if it was a better approach, and it needs some help.
There's a section wherein I wanted to substitute the old endpoints with new endpoints.
I wanted to use entmod, entdel and entupd. But I did not have much success.
Can somebody please see if they can incorporate all these for learning purposes.
Different versions are welcome.
(defun c:test (/ Lay CLay FRad L1 L1m Ln ent Lay L2 L2e L2m L3 L3m L4 L4m int1 int2 ang1 ang2 L1x L2x L3x L4x)
(if (not LipDistance) (setq LipDistance (* (getvar "Dimscale") 0.0625)))
(setq CLay (getvar"cLayer"))
(setvar "cmdecho" 0)
(setvar "orthomode" 0)
(princ "\nSelect the lines couter-clockwise. ")
(setq L1 (entsel "\nEnter OUTSIDE of branch duct<Nearest>: "))
(setq L1a (cdr (assoc 10 (entget (car L1)))))
(setq L1b (cdr (assoc 11 (entget (car L1)))))
(setq Lay (cdr (assoc 8 (entget (car L1)))))
(setq L2 (entsel "\nEnter INSIDE of branch duct<Perpendicular>: "))
(setq L2a (cdr (assoc 10 (entget (car L2)))))
(setq L2b (cdr (assoc 11 (entget (car L2)))))
(setq L3 (entsel "\nEnter INSIDE of main duct<Nearest>: "))
(setq L3a (cdr (assoc 10 (entget (car L3)))))
(setq L3b (cdr (assoc 11 (entget (car L3)))))
(setq L4 (entsel"\nEnter Opposite side of main duct<Perpendicular>: "))
(setq L4a (cdr (assoc 10 (entget (car L4)))))
(setq L4b (cdr (assoc 11 (entget (car L4)))))
(setq int1 (inters L1a L1b L4a L4b nil))
(setq int2 (inters L2a L2b L3a L3b nil))
(if (> (distance L1a int1) (distance L1b int1))(setq L1x L1a)(setq L1x L1b))
(if (> (distance L4a int1) (distance L4b int1))(setq L4x L4a)(setq L4x L4b))
(if (> (distance L2a int2) (distance L2b int2))(setq L2x L2a)(setq L2x L2b))
(if (> (distance L3a int2) (distance L3b int2))(setq L3x L3a)(setq L3x L3b))
(setq ang1 (angle int2 L2x))
(setq ang2 (angle int2 L3x))
;===================please modify this section===========================
(command "erase" L1 L2 L3 L4 "")
(command "_.-layer" "s" Lay "")
(command "line" L1x Int1 "")
(setq L1 (cdr (assoc 10 (entget (entlast)))))
(command "line" L2x Int2 "")
(command "line" L4x Int1 "")
(setq L4 (cdr (assoc 10 (entget (entlast)))))
(command "line" L3x Int2 "")
;========================================================================
(DrawLines)
(command "_.-layer" "s" cLay "" )
(princ "\nDone...")
(princ)
)
(defun DrawLines ()
(command "line" "_non"int1 "_non"int2 "")
(command "line" "_non" (polar int2 ang1 LipDistance) "_non"(osnap L1 "perp") "")
(command "line" "_non"(polar int2 ang2 LipDistance) "_non"(osnap L4 "perp") "")
)