Find Circles and add additional circle

Find Circles and add additional circle

inulobo
Advocate Advocate
1,491 Views
10 Replies
Message 1 of 11

Find Circles and add additional circle

inulobo
Advocate
Advocate

I am trying to find all circles of a particular diameter then add an additional circle of a particular diameter to the center of each circle. How do I go about this? Using the code below for selecting all circles. 

 

(defun c:CSC  (/ cEnt ssgrip)
  (setq tol 0.05)  ; <<-- Tolerance
  (if (setq cEnt (car (entsel "\nSelect Circle: ")))
    (progn
      (setq rad (cdr (assoc 40 (entget cEnt))))
      (sssetfirst nil
        (ssget "_X"
               (list '(0 . "CIRCLE")
                     '(-4 . ">=")
                     (cons 40 (- rad tol))
                     '(-4 . "<=")
                     (cons 40 (+ rad tol)))))
      (alert (strcat "Radius = " (rtos rad 2 2))))
    (princ "\n<!> Nothing Selected <!>"))
  (princ))

 

0 Likes
Accepted solutions (2)
1,492 Views
10 Replies
Replies (10)
Message 2 of 11

pbejse
Mentor
Mentor

@inulobo wrote:

I am trying to find all circles of a particular diameter then add an additional circle of a particular diameter to the center of each circle. How do I go about this? Using the code below for selecting all circles. 


 

What will be the radius of the additional circle? via user prompt? or based on the current radius of the selected circles?

 

0 Likes
Message 3 of 11

inulobo
Advocate
Advocate

I would prefer a user prompt or even the ability to add a default value. 

0 Likes
Message 4 of 11

pbejse
Mentor
Mentor
Accepted solution

@inulobo wrote:

I would prefer a user prompt or even the ability to add a default value. 


Using most parts of the orignal lisp

 

(defun c:CSC  (/ cEnt rad ss i ent)
  (setq tol 0.05)  ; <<-- Tolerance

  (setq Nrad (cond
	((getdist (strcat "\nEnter Radius"
                 (if Nrad (strcat " <" (rtos Nrad) ">: ") ": ")
                            )))(Nrad))
                )

  (if (and
	(setq cEnt (car (entsel "\nSelect Circle: ")))
	(setq rad (cdr (assoc 40 (entget cEnt))))
	(setq ss (ssget	"_X"
			(list '(0 . "CIRCLE")
			      '(-4 . ">=")
			      (cons 40 (- rad tol))
			      '(-4 . "<=")
			      (cons 40 (+ rad tol))
			)
		 )
	)
	);and
    (repeat (setq i (sslength ss))
	(setq ent (entget (ssname ss (setq i (1- i)))))
     
    	  (entmakex
	    (subst (Cons 40 Nrad) (assoc 40 ent) ent))
      )
    (princ "\n<!> Nothing Selected <!>"))

  (princ)
)

 

 HTH

0 Likes
Message 5 of 11

inulobo
Advocate
Advocate

Thank you! If I wanted to use this for diameters instead of radiuses what do I have to do? I am not too familiar with lisp.

0 Likes
Message 6 of 11

pbejse
Mentor
Mentor

@inulobo wrote:

Thank you! If I wanted to use this for diameters instead of radiuses what do I have to do? I am not too familiar with lisp.


You mean prompt for Diameter instead of radius?

Change this

(entmakex
	    (subst (Cons 40 Nrad) (assoc 40 ent) ent))

to

(entmakex
	    (subst (Cons 40 (* 0.5 Nrad)) (assoc 40 ent) ent))

Also change the radius to Diameter on the prompt.

 

HTH

0 Likes
Message 7 of 11

inulobo
Advocate
Advocate

Thanks. I was wondering were it took that into account. 

0 Likes
Message 8 of 11

hak_vz
Advisor
Advisor
Accepted solution

Try this

 

 

(defun c:circleInCircle ( / r f sel_list fil ss i)

(setq r (getreal "\nEnter circle diameter to insert: "))
(setq i 0)
(while (> (strlen (setq f (getstring (strcat "\nEnter " (itoa (setq i (1+ i))) ". radius selection filter: ")))) 0)
	(setq fil (cons (list (substr f 1 1)(atof (substr f 2))) fil))
) 
(setq sel_list (list(cons -4 "<and")))
(foreach e fil (setq sel_list (append sel_list (list(cons -4 (car e)))))(setq sel_list (append sel_list (list(cons 40 (cadr e))))))
(setq sel_list (append sel_list (list(cons -4 "and>"))))
(setq ss (ssget "X" (append (list (cons 0 "CIRCLE")) sel_list)))
(cond 
	((and ss)
		(setvar 'cmdecho 0)
		(setq i -1)
		(while (< (setq i (1+ i)) (sslength ss))
			(setq c (cdr (assoc 10 (entget (ssname ss i)))))
			(command "_.circle" "_non" c r)
		)
		(setvar 'cmdecho 0)	
	)
)
(princ)
)

 

 

 

Command: CIRCLEINCIRCLE
Enter circle diameter to insert: 2
Enter 1. radius selection filter: >3
Enter 2. radius selection filter: <8
Enter 3. radius selection filter:

 

 

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 9 of 11

inulobo
Advocate
Advocate

I don't understand exactly what you did here. Ill either be all in radius or all in diameter. Are you trying to set a search to find radius or diameter within that range? 

0 Likes
Message 10 of 11

hak_vz
Advisor
Advisor

Radius. You can modify it to select diameter as @pbejse  has shown. Code asks you to enter radius of a circle to be inserted an then you can enter one or more filters to select circle candidates. In my example I selected all circles with radius greater than 3 and smaller than 8.

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 11 of 11

inulobo
Advocate
Advocate

Thank you!

0 Likes