Draw *line between selected blocks and nearby blocks

Draw *line between selected blocks and nearby blocks

jtm2020hyo
Collaborator Collaborator
2,789 Views
5 Replies
Message 1 of 6

Draw *line between selected blocks and nearby blocks

jtm2020hyo
Collaborator
Collaborator

I need select multiple blocks and use a lisp to draw a line since selected blocks-base-point to their nearby block (base poin to base point).  all those blocks to link are different.

0 Likes
Accepted solutions (1)
2,790 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

Post an image or sample drawing.  Even without one, questions come to mind.  What is "nearby"?  The nearest one only, no matter how far away?  More than one if they are within a certain distance?  Nearby as distance between insertion points, or distance between any parts on the Blocks?  Etc.

Kent Cooper, AIA
Message 3 of 6

jtm2020hyo
Collaborator
Collaborator

sorry for my bad English.

...and yes you are right. I mean the "nearest" block.


Here is imagen:


image.png

0 Likes
Message 4 of 6

dbhunia
Advisor
Advisor
Accepted solution

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....
Message 5 of 6

jtm2020hyo
Collaborator
Collaborator

@dbhunia wrote:

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)
)
)

 

 


thanks. this work for me. you are pretty smart.

Is possible to select multiple different blocks?

and create multiple prompt with rules like:

1 allow draw *line between block with the same name (y/n)
2 only draw *line between blocks same layer  (y/n)
3 allow selected block with mouse  (y/n)
4 select "one block name" to link with "another block name"  (y/n)

0 Likes
Message 6 of 6

jtm2020hyo
Collaborator
Collaborator

@dbhunia wrote:

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)
)
)

 

 


Is possible to draw a line between the selected block-base-point with the nearest block over defined angle?

In my example, I linked circles with the nearest block over 180 grades axis +Y :

 

image.png

0 Likes