Look for the Xref name: "Drawing-Frame" If it is found detach it / if not found leave.
(if (search for the Xref name "Drawing-Frame")
(command "_-xref" "detach" "Drawing-Frame" ) (princ "\n--> No any Xref name found on - Drawing-Frame."))
Look for the Xref name: "Proposed_Building_Plan" If it is not found insert it / if it is found leave.
(if [color=blue](not [/color](search for the Xref name "Proposed_Building_Plan")[color=blue])[/color]
(command "_-xref" "overlay" "D:\\Proposed_Building_Plan.dwg" "0,0,0" "" "" "") (princ "\n--> The Xref name Proposed_Building_Plan is already inserted."))
How to search for the Xref
Note: I correct in blue