Place circles around blocks

Place circles around blocks

khirunath
Contributor Contributor
657 Views
12 Replies
Message 1 of 13

Place circles around blocks

khirunath
Contributor
Contributor

I have a blocks named DA_LE3 in the drawing and I want to place a circles around them in a single shot. Is anyone have already created a lisp code similar to this requirement? or so any assistance from anyone is greatly appreciated. Thank you.

(Circle radius should be 24 & color blue)

0 Likes
Accepted solutions (3)
658 Views
12 Replies
Replies (12)
Message 2 of 13

hak_vz
Advisor
Advisor

@khirunath 

Try this.

 

(defun c:bcir (/ ss i )
	(setq ss (ssget "X" '((0 . "INSERT")(2 . "DA_LE3"))) i -1)
	(cond
		((and ss)
			(while (< (setq i (1+ i)) (sslength ss))
				(entmake
					(list
						(cons 0 "CIRCLE")
						(cons 100 "AcDbEntity")
						(cons 100 "AcDbCircle")
						(cons 10 (cdr(assoc 10 (entget (ssname ss i)))))
						(cons 40 24)
						(cons 62 5)
					)
				)
			)
		)
	)
	(princ)
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 13

pbejse
Mentor
Mentor
Accepted solution

@khirunath wrote:

I have a blocks named DA_LE3 in the drawing and I want to place a circles around them in a single shot. Is anyone 

(Circle radius should be 24 & color blue)


 

Center of block | Radius 24

(Defun c:BlueCirle (/ Bc i)
  (if (setq Bc (ssget "_X" '((0 . "INSERT") (2 . "DA_LE3,`*U*"))))
    (repeat (setq i (sslength bc))
      (if (eq (strcase
		(getpropertyvalue
		  (setq e (ssname Bc (setq i (1- i))))
		  "BlockTableRecord/Name"
		)
	      )
	      "DA_LE3"
	  )
	(progn
	  (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
	  (Setq pdata (mapcar '(lambda (p)
			(vlax-safearray->list p)
				 ) (list ll ur)))
	  (Setq mdpt (mapcar (function (lambda (a b) (/ (+ a b) 2.)))
			     (CAr pdata)(cadr pdata)))		
		(entmakex (list	(cons 0 "CIRCLE")
				(Cons 10 mdpt)
				(cons 62 5)
				(cons 40 24)
			  )
		)
	  )
      )
    )
  )
  (princ)
)

Center of block | Radius size of block

(Defun c:BlueCirle (/ Bc i pdata mdpt rad)
  (if (setq Bc (ssget "_X" '((0 . "INSERT") (2 . "DA_LE3,`*U*"))))
    (repeat (setq i (sslength bc))
      (if (eq (strcase
		(getpropertyvalue
		  (setq e (ssname Bc (setq i (1- i))))
		  "BlockTableRecord/Name"
		)
	      )
	      "DA_LE3"
	  )
	(progn
	  (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
	  (Setq pdata (mapcar '(lambda (p)
			(vlax-safearray->list p)
				 ) (list ll ur)))
	  (Setq mdpt (mapcar (function (lambda (a b) (/ (+ a b) 2.)))
			     (CAr pdata)(cadr pdata)))
	  (setq rad (distance mdpt (cadr pdata)))		
		(entmakex (list	(cons 0 "CIRCLE")
				(Cons 10 mdpt)
				(cons 62 5)
				(cons 40 rad)
			  )
		)
	  )
      )
    )
  )
  (princ)
)

 

HTH

 

Message 4 of 13

Kent1Cooper
Consultant
Consultant

[The suggestions so far use the Block insertion point for the center of the Circle.  If the Block insertion point is not in the center of it, but you want the Circles centered around the Blocks' drawn contents, that can also be done, using their bounding boxes.]

Kent Cooper, AIA
Message 5 of 13

khirunath
Contributor
Contributor

Yes you are correct, the Block insertion point is not in the center of it. I need circles to be centered around the block. Both above 2 codes are working fine, but circles are not in centered to block.

0 Likes
Message 6 of 13

pbejse
Mentor
Mentor

@khirunath wrote:

Yes you are correct, the Block insertion point is not in the center of it. I need circles to be centered around the block. Both above 2 codes are working fine, but circles are not in centered to block.


Of still the same radius? does it depend on the size of the block?

Code updated at post # 3 for rad = 24 and rad = size of block

 

Message 7 of 13

khirunath
Contributor
Contributor

Hi, thanks. Your code is working but circles are not centered to the blocks.

0 Likes
Message 8 of 13

khirunath
Contributor
Contributor

Thank you. second one is fine with radius size of block. 

0 Likes
Message 9 of 13

hak_vz
Advisor
Advisor
Accepted solution

 

Next time attach sample drawing and add detailed description of your problem.

 

(defun c:bcir (/ ss i a b pt)
	(setq ss (ssget "X" '((0 . "INSERT")(2 . "DA_LE3"))) i -1)
	(cond
		((and ss)
			(while (< (setq i (1+ i)) (sslength ss))
			(vlax-invoke-method (vlax-ename->vla-object(ssname ss i))'getboundingbox 'a 'b)
			(setq a (vlax-safearray->list a)b (vlax-safearray->list b))
			(setq pt (mapcar '* (mapcar '+ a b) '(0.5 0.5)))
				(entmake
					(list
						(cons 0 "CIRCLE")
						(cons 100 "AcDbEntity")
						(cons 100 "AcDbCircle")
						(cons 10 pt)
						(cons 40 24)
						(cons 62 5)
					)
				)
			)
		)
	)
	(princ)
)

 

To add other blocks to selection add them to selection filter

(2 . "DA_LE3,name1,name2")

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 13

pbejse
Mentor
Mentor

@khirunath wrote:

Thank you. second one is fine with radius size of block. 


 

Good for you, glad it helps.

 

Message 11 of 13

khirunath
Contributor
Contributor

Hi, Can it be possible to add another block into the same code? or it required separate variables?

0 Likes
Message 12 of 13

pbejse
Mentor
Mentor
Accepted solution

@khirunath wrote:

Hi, Can it be possible to add another block into the same code? or it required separate variables?


You can add block names here. [ in blue ]

(Defun c:BlueCirle (/ Bc i pdata mdpt rad)
  (if (setq Bc (ssget "_X" '((0 . "INSERT") (2 . "DA_LE3,`*U*,BLOCK1,BLOCK2"))))
    (repeat (setq i (sslength bc))
      (if (member  (strcase
		(getpropertyvalue
		  (setq e (ssname Bc (setq i (1- i))))
		  "BlockTableRecord/Name"
		)
	      )
	      '("DA_LE3" "BLOCK1" "BLOCK2" ))
	(progn
	  (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
	  (Setq pdata (mapcar '(lambda (p)
			(vlax-safearray->list p)
				 ) (list ll ur)))
	  (Setq mdpt (mapcar (function (lambda (a b) (/ (+ a b) 2.)))
			     (CAr pdata)(cadr pdata)))
	  (setq rad (distance mdpt (cadr pdata)))		
		(entmakex (list	(cons 0 "CIRCLE")
				(Cons 10 mdpt)
				(cons 62 5)
				(cons 40 rad)
			  )
		)
	  )
      )
    )
  )
  (princ)
)

HTH

0 Likes
Message 13 of 13

khirunath
Contributor
Contributor

Sure, Thanks

0 Likes