Hi
Try this........(keep it in mind the total number of selected block must be less than the total number of nearby other blocks)
(defun C:BBL ( / )
(vl-load-com)
(setq SB_lst nil)
(setq NB_lst nil)
(princ "\nSelect a block(For Block Name) from which you want to draw line to Nearby Block (Other than Selected block)")
(Setq SB_Name (cdr (assoc 2 (entget(car(entsel))))))
(Setq selectionset (ssget "_A" '((0 . "INSERT"))))
(repeat (setq N (sslength selectionset))
(setq Data (ssname selectionset (setq N (- N 1))))
(setq EntityData (entget Data))
(setq B_Name (cdr (assoc 2 EntityData)))
(setq BP_Block (cdr (assoc 10 EntityData)))
(if (= SB_Name B_Name)
(setq SB_lst (cons BP_Block SB_lst))
(setq NB_lst (cons BP_Block NB_lst))
)
)
(repeat (setq N (length SB_lst))
(setq BP_SB (nth (setq N (- N 1)) SB_lst))
(setq DIS_lst nil)
(repeat (setq N1 (length NB_lst))
(setq BP_NB (nth (setq N1 (- N1 1)) NB_lst))
(setq PD (distance BP_SB BP_NB))
(setq DIS_lst (cons PD DIS_lst))
)
(setq LDP (vl-position (apply 'min DIS_lst) DIS_lst))
(setq NP (nth LDP NB_lst))
(command "line" BP_SB NP "")
(princ)
)
)
Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....