Bro i made some changes in the lisp routine , now it works only when i turn of the pgl layer , it prompts to select an object on the targeted layer , but i think it needs further changes , kindly check the lisp and the attached .dwg file. Thanks
(defun c:Tdsn (/ s p1 p2 p3 px1 px2 ldat epol p spb layer)
;; Prompt to select an object on the desired layer
(prompt "\nSelect an object on the target layer: ")
(setq s (ssget ":E" '((0 . "*"))))
(if s
(setq layer (cdr (assoc 8 (entget (ssname s 0)))))
(prompt "\nNo object selected."))
;; Proceed if a layer is selected
(if layer
(progn
(while (and
(setq p1 (getpoint "\nPick Point 1 : ")
p2 (getpoint p1 "\nPick Point 2 : ")
p3 (getpoint p2 "\nPick Point 3 : "))
)
(setq
px1 (list (car p1) (cadr p3))
px2 (list (car p2) (cadr p3))
ldat (list px1 px2))
;; Lwpolyline previa
(entmakex (append (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
(cons 90 4))
(mapcar
'(lambda (j) (cons 10 j))
(list p1 px1 px2 p2))))
(setq epol (entlast))
;; Creacion de Polilinea con Boundary
(setq p (mapcar '+ p3 '(0 0.5 0)))
(command "_.boundary" "_non" p "")
(command "_.erase" epol "")
;; Remueve puntos de la base en Polilinea Boundary
(setq spb (entget (entlast)))
(foreach x ldat
(setq spb
(vl-remove-if '(lambda (n) (equal (cons 10 x) n 0.01)) spb)))
(entmod (append spb (list (cons 62 1))))
(entmod (subst (cons 70 0) (assoc 70 spb) spb)))
;; Filter objects by layer
(setq s (ssget "X" (list (cons 8 layer) (cons 0 "LINE,POLYLINE,INSERT"))))
(while (setq p (ssname s 0))
;; Process the object based on type
(setq type (cdr (assoc 0 (entget p))))
(cond
((= type "LINE")
;; Process line object
)
((= type "LWPOLYLINE")
;; Process polyline object
)
((= type "INSERT")
;; Process block object
))
(ssdel p s)))
(prompt "\nNo layer selected."))
(princ))
(princ "TDSN command loaded.\n")