Jump to content

if condition not working in delete circles using diameter


ajithkumar.t

Recommended Posts

(defun c:deleteCirclesByDiameter ()
  (setq f 0.5000)
  (setq ss (ssget "_X" '((0 . "CIRCLE"))))
  (if ss
      (progn
        (setq index 0)
        (repeat (sslength ss)
          (setq ent (ssname ss index))
          (if ent
              (progn
                (setq diameter (cdr (assoc 40 (entget ent))))
                (setq dia (* diameter 2))
                (prompt (strcat "\nCircle: " (itoa (1+ index))
                                ", Diameter: " (rtos dia 2 4)))
(if (and (> x f)
         (< dia x) 
         (not (= dia 0.6875 x 0.75))
         (not (= dia 0.6880 x 0.75)))
                            (progn
                              (entdel ent)
                              (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                                              ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
                              )
                          (progn
                            (entdel ent)
                            (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                                            ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
                            )
                          )
	                      (progn
                        (entdel ent)
                        (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                                        ", Diameter: " (rtos dia 2 4)))
                        )
                      )
                )
              (setq index (1+ index))
              )
            )
          )
        (prompt "\nCircles with diameter less than x have been deleted.")
        )
      (prompt "\nNo circles found in the drawing.")
     )
  (princ)
)

In this code, help me to fix my mistakes in if conditions..

Link to comment
Share on other sites

2 hours ago, ajithkumar.t said:
(if (and (> x f)

you do not assign x a value within your defun.

also these last functions are not within your defun, some brackets are set wrong.
image.png.890287704326f388471ba9fe00e2d53a.png

Edited by EnM4st3r
Link to comment
Share on other sites

2 hours ago, ajithkumar.t said:
         (not (= dia 0.6875 x 0.75))
         (not (= dia 0.6880 x 0.75))

these are useless since the output is t no matter what

Link to comment
Share on other sites

i would try using less progn functions.

and whats the use of that if function? its the same 'then' and 'else' expression

(if (and (> x f)
      (< dia x) 
      (not (= dia 0.6875 x 0.75))
      (not (= dia 0.6880 x 0.75))
    )
  (progn
    (entdel ent)
    (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                    ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
  )
  (progn
    (entdel ent)
    (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                    ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
  )
)


also you are using entdel rigth after the if function again wich would instead of delete restore that object again.
 

 

Edited by EnM4st3r
Link to comment
Share on other sites

this is basically the same function as yours but with most of the progns removed.
 

but the other problems i said are still here:

  • double entdel -> does nothing
  • if 'then' and 'else' expression are the same
  • using 'x' within the if function but that gets set nowhere
     
(defun c:deleteCirclesByDiameter (/ ss)
  (setq f 0.5000)
  (setq ss (ssget "_X" '((0 . "CIRCLE"))))
  (if (not ss) (progn (prompt "\nNo circles found in the drawing.") (exit)))
 
  (setq index 0)
  (repeat (sslength ss)
    (setq ent (ssname ss index))
    (setq dia (* 2 (cdr (assoc 40 (entget ent)))))
    (prompt (strcat "\nCircle: " (itoa (1+ index))
                    ", Diameter: " (rtos dia 2 4)))
    
    (entdel ent)
    (if (and (> x f) (< dia x))
        (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                        ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
        (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                        ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
    )
    (entdel ent)
    (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                      ", Diameter: " (rtos dia 2 4)))
    (setq index (1+ index))
  )
  (prompt "\nCircles with diameter less than x have been deleted.")
  (princ)
)

 

Edited by EnM4st3r
  • Like 1
Link to comment
Share on other sites

Hi mate, what i want is if diameter will be 0.6875 or 0.6880 and x=0.75.. circles should not be deleted. otherwise delete all circles 

Link to comment
Share on other sites

6 minutes ago, ajithkumar.t said:

Hi mate, what i want is if diameter will be 0.6875 or 0.6880 and x=0.75.. circles should not be deleted. otherwise delete all circles 

 

so i guess that would be the if condition.
 

(if (and (> x f)
         (< dia x)
         (not (member dia '(0.6875 0.6880)))
         (not (= x 0.75))   
    )
 ;....
)

 

Link to comment
Share on other sites

alright, see if that works

 

(defun c:deleteCirclesByDiameter (/ ss)
  (setq f 0.5000)
  (setq ss (ssget "_X" '((0 . "CIRCLE"))))
  (if (not ss) (progn (prompt "\nNo circles found in the drawing.") (exit)))
 
  (setq index 0)
  (repeat (sslength ss)
    (setq ent (ssname ss index))
    (setq dia (* 2 (cdr (assoc 40 (entget ent)))))
    (prompt (strcat "\nCircle: " (itoa (1+ index))
                    ", Diameter: " (rtos dia 2 4)))
    (if (and (> x f)
             (> x dia)
             (not (member dia '(0.6875 0.6880)))
             (not (= x 0.75))   
        )
        (progn
          (entdel ent)
          (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                        ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
        )
        (prompt (strcat "\nSkipped Circle: " (itoa (1+ index))
                        ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
    )
    (setq index (1+ index))
  )
  (prompt "\nCircles with diameter less than x have been deleted.")
)

 

Link to comment
Share on other sites

yes. this is first condition  (> x f) it it false there is no deletion process needed.

 

 

Edited by ajithkumar.t
Link to comment
Share on other sites

so its skipping every cirlce because of the conditions..

 

what example circle do you want to be deleted and what example x value would you have?

Link to comment
Share on other sites

5 minutes ago, ajithkumar.t said:

this is first condition  (> x f) it it false there is no deletion process needed.

yes, it does that

Link to comment
Share on other sites

second one is (> dia x) after these conditions true then deletion will start if any circle has  dia=0.6875 or 0.6880 when thickness x=0.75, no need to delete those..there is any circles with other values it should be deleted. 

Link to comment
Share on other sites

1 minute ago, ajithkumar.t said:

second one is (> dia x) after these conditions true then deletion will start if any circle has  dia=0.6875 or 0.6880 when thickness x=0.75, no need to delete those..there is any circles with other values it should be deleted. 


it should do exactly that.. can you give example file?

Link to comment
Share on other sites

7 minutes ago, ajithkumar.t said:

if any circle has  dia=0.6875 or 0.6880 when thickness x=0.75,

ah i thought always if thickness 0.75 dont delete.

Try this:
 

(defun c:deleteCirclesByDiameter (/ ss diaexception)
  (setq f 0.5000)
  (setq ss (ssget "_X" '((0 . "CIRCLE"))))
  (setq diaexception '(0.6875 0.6880))
  (if (not ss) (progn (prompt "\nNo circles found in the drawing.") (exit)))
 
  (setq index 0)
  (repeat (sslength ss)
    (setq ent (ssname ss index))
    (setq dia (* 2 (cdr (assoc 40 (entget ent)))))
    (if (and (> x f)
             (> x dia)
             (not (and (member dia diaexception) (= x 0.75)))
        )
        (progn
          (entdel ent)
          (prompt (strcat "\nDeleted Circle: " (itoa (1+ index))
                        ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
        )
        (prompt (strcat "\nSkipped Circle: " (itoa (1+ index))
                        ", Diameter: " (rtos dia 2 4) ", Thickness: " (rtos x 2 4)))
    )
    (setq index (1+ index))
  )
  (prompt "\nCircles with diameter less than x have been deleted.")
)

 

Edited by EnM4st3r
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...