Condition for selecting block by diameter of circle

Condition for selecting block by diameter of circle

avinash00002002
Collaborator Collaborator
235 Views
2 Replies
Message 1 of 3

Condition for selecting block by diameter of circle

avinash00002002
Collaborator
Collaborator

Hi!

 

I have a some circles like diameter of 16, 17.5 18, 12, 13, 13.5 14 etc...

 

if 16 to 18 diameter of circle found then insert "H1" block

if 11 to 14 diameter of circle found then insert "H2" block

if 20 to 22 diameter of circle found then insert "H3" block

if 24 to 26 diameter of circle found then insert "H4" block

 

any suggestion,

 

Thanks,

 

Avinash Patil

0 Likes
236 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant

That should not be difficult, but a question:  What should happen with a selected Circle whose diameter is not within one of those ranges, such as 15, or 23?  Nothing?  Insert some default none-of-the-above Block?  Notify the User?

EDIT:  Wait!  Relational testing with (-4) entries is powerful enough that it's possible to have it allow selection of only Circles whose diameters fall within those ranges, and ignore others.  In simplest terms, and minimally tested:

 

(defun C:TEST (/ ss n cir rad)
  (if
    (setq ss
      (ssget
        '( ; filter list
          (0 . "CIRCLE")
          (-4 . "<OR")
            (-4 . "<AND") (-4 . ">=") (40 . 5.5) (-4 . "<=") (40 . 7.0) (-4 . "AND>")
            (-4 . "<AND") (-4 . ">=") (40 . 8.0) (-4 . "<=") (40 . 9.0) (-4 . "AND>")
            (-4 . "<AND") (-4 . ">=") (40 . 10.0) (-4 . "<=") (40 . 11.0) (-4 . "AND>")
            (-4 . "<AND") (-4 . ">=") (40 . 12.0) (-4 . "<=") (40 . 13.0) (-4 . "AND>")
          (-4 . "OR>")
        ); filter list
      ); ssget
    ); setq
    (repeat (setq n (sslength ss)); then
      (setq
        cir (ssname ss (setq n (1- n)))
        rad (getpropertyvalue cir "Radius")
      ); setq
      (command "_.insert"
        (cond
          ((<= rad 7.0) "H2")
          ((<= rad 9.0) "H1")
          ((<= rad 11.0) "H3")
          ("H4")
        ); cond
        "_non" (getpropertyvalue cir "Center") "" "" ""
      ); command
    ); repeat
  ); if
  (prin1)
)

 

[Of course that's all based on the radius, not the diameter, because the radius of a Circle is what entity data stores, and therefore is what can be filtered for in (ssget).]

Kent Cooper, AIA
0 Likes
Message 3 of 3

komondormrex
Mentor
Mentor

hey,

another one

 

 

(defun c:insert_h_block (/ target_circle_sset block_name diameter)
	(setq target_circle_sset (ssget '((0 . "circle"))))
	(if target_circle_sset 
		(foreach circle (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex target_circle_sset))))
			(setq block_name
					(cond
						((<= 16 (setq diameter (vla-get-diameter circle)) 18) "h1")
						((<= 11 diameter 14) "h2")
						((<= 20 diameter 22) "h3")
						((<= 24 diameter 26) "h4")
						(t nil)
					)
          	) 
			(if block_name
				(vla-insertblock (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
								 (vla-get-center circle)
								 block_name
								 1 1 1 0
				)
			)
		)
	)
	(princ)
)

 

 

 

 

0 Likes