Hi
The last code may be solved your problem........ But it will fail for the below reasons.......
If your selected block (non dynamic block) is named like "xxxxxUxxxx" or block name containing "U" .........
Then the below RED marked line become "T"......
For that reason code will go for BLUE marked line (to get the name of dynamic block)..... and the code will fail .....
(defun C:BBL (/);;Put Temp Variables here.....
....................
(Setq SB_Name (cdr (assoc 2 (setq Data (entget(car(entsel "\nSelect a block(For Block Name) from which you want to draw line to Nearby Block (Other than Selected block)")))))))
(if (= (wcmatch SB_Name "*U*") T)
(Setq SB_Name (vla-get-Effectivename (vlax-ename->vla-object (cdr (assoc -1 Data)))))
)
(Setq selectionset_SB (BLOCKSSET SB_Name))
(initget 1 "Block Layer")
(setq NBO (getkword "\nSelect Nearest Objects by [Block Name/Layer Name]: "))
(if (= NBO "Block")
(progn
(princ "BLOCK")
(Setq NSB (cdr (assoc 2 (setq Data1 (entget(car(entsel "\nSelect a Nearby Block upto which you want to draw line....")))))))
(if (= (wcmatch NSB "*U*") T)
(Setq NSB (vla-get-Effectivename (vlax-ename->vla-object (cdr (assoc -1 Data1)))))
)
(Setq selectionset_NB (BLOCKSSET NSB))
....................
So it is my suggestion to use the corrected code below......
(defun C:BBL (/);;Put Temp Variables here.....
(vl-load-com)
(setq SB_lst nil)
(setq NB_lst nil)
(Setq SB_Name (cdr (assoc 2 (setq Data (entget (setq PBP (car(entsel "\nSelect a block(For Block Name) from which you want to draw line to Nearby Block (Other than Selected block)"))))))))
(if (= :vlax-true (vla-get-IsDynamicBlock (vlax-ename->vla-object PBP)))
(Setq SB_Name (vla-get-Effectivename (vlax-ename->vla-object (cdr (assoc -1 Data)))))
)
(Setq selectionset_SB (BLOCKSSET SB_Name))
(initget 1 "Block Layer")
(setq NBO (getkword "\nSelect Nearest Objects by [Block Name/Layer Name]: "))
(if (= NBO "Block")
(progn
(princ "BLOCK")
(Setq NSB (cdr (assoc 2 (setq Data1 (entget (setq PBP1 (car(entsel "\nSelect a Nearby Block upto which you want to draw line...."))))))))
(if (= :vlax-true (vla-get-IsDynamicBlock (vlax-ename->vla-object PBP1)))
(Setq NSB (vla-get-Effectivename (vlax-ename->vla-object (cdr (assoc -1 Data1)))))
)
(Setq selectionset_NB (BLOCKSSET NSB))
)
(progn
(princ "LAYER")
(Setq NSBL (cdr (assoc 8 (entget(car(entsel "\nSelect a Object for Layer which contain Nearby Block upto which you want to draw line...."))))))
(Setq selectionset_NB (ssget "_A" (list '(0 . "INSERT") (cons 8 NSBL))))
)
)
(repeat (setq N (sslength selectionset_SB))
(setq BP_Block (cdr (assoc 10 (entget (ssname selectionset_SB (setq N (- N 1)))))))
(setq SB_lst (cons BP_Block SB_lst))
)
(repeat (setq N (sslength selectionset_NB))
(setq BP_Block (cdr (assoc 10 (entget (ssname selectionset_NB (setq N (- N 1)))))))
(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 "_.pline" BP_SB NP "")
(princ)
)
)
(defun BlockSSET (blname / sset ss-dyn num ent effname)
(vl-load-com)
(if (not (setq sset (ssget "X" (list (cons 2 blname)))))
(setq sset (ssadd))
)
(if (setq ss-dyn (ssget "X" (list (cons 2 "`*U*"))))
(progn
(setq num 0)
(repeat (sslength ss-dyn)
(setq ent (ssname ss-dyn num))
(setq effname (vla-get-EffectiveName (vlax-ename->vla-object ent)))
(if (= blname effname)
(ssadd ent sset)
)
(setq num (1+ num))
)
)
)
sset
)
Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....