ajithkumar.t Posted November 19, 2024 Posted November 19, 2024 (defun c:deleteCirclesByDiameter (/ ss diaexception f x ) (setq f 0.5000) (setq x globalCleanedValue) (setq ss (ssget "_X" '((0 . "CIRCLE")))) (setq diaexception '(0.6875 0.6880)) (if ss (progn (prompt (strcat "\nFormatted Value of x: " (rtos x 2 4))) (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.") ) (prompt "\nNo circles found in the drawing.") ) (princ) ) This is the code for deleting circles based on some condtion, i have attached sample dxf, in that dxf file if my condition is true circles will be deleted, now what i want is for the same condition slots also should be delete if conditions true....thanks in advance.. Quote
Emmanuel Delay Posted November 19, 2024 Posted November 19, 2024 Can you upload a dwg file of that? Quote
ajithkumar.t Posted November 19, 2024 Author Posted November 19, 2024 yeah sure..find the attchament below. sample.dwg Quote
Emmanuel Delay Posted November 19, 2024 Posted November 19, 2024 So you want the cyan slot to also disappear, right? Just one thing, what's globalCleanedValue ? What value does it have? It's glogal, so declared outside the function Quote
ajithkumar.t Posted November 19, 2024 Author Posted November 19, 2024 (edited) Yes that cyan slot. globalCleanedValue is a decimal value..for the above dwg, globalCleanedValue is 0.5 which I got from "1/2" of "PROFILE:PL1/2". This value will varies depends on the dwg. Edited November 19, 2024 by ajithkumar.t Quote
Emmanuel Delay Posted November 21, 2024 Posted November 21, 2024 It took me some time to handle some things I thought would be trivial. See if this works as you want. ;; https://www.cadtutor.net/forum/topic/93789-how-to-delete-slots-in-dxf/ (setq globalCleanedValue 1.2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; test of diameter_of_slot (defun c:test_dos ( / ent) (setq ent (car (entsel))) (diameter_of_slot ent) ) (defun same_list_float (l1 l2 / i res smallnumber) (setq smallnumber 0.000001) (setq i 0) (setq res T) (repeat (length l1) (if (< (abs (- (nth i l1) (nth i l2))) smallnumber) (progn ;;(princ " ") ;;(princ (abs (- (nth i l1) (nth i l2)))) (setq res nil) ) ) (setq i (+ i 1)) ) res ) ;; this function looks if the polyline is two parallel lines, connected by 2 arcs. ;; It will return the distance between the parallel lines, which is also the diameter of the arcs. ;; feel free to improve this function (defun diameter_of_slot (ent / pts blgs lst pair) (setq pts (list)) (setq blgs (list)) (setq lst (entget ent)) (while (setq pair (assoc 42 lst)) (setq blgs (append blgs (list (cdr pair)))) (setq lst (cdr (member pair lst))) ;; removes the item we just looked at ) (setq lst (entget ent)) (while (setq pair (assoc 10 lst)) (setq pts (append pts (list (cdr pair)))) (setq lst (cdr (member pair lst))) ;; removes the item we just looked at ) (setq dst nil) (if ;; line, arc, line, arc (or (same_list_float blgs (list -1.0 0.0 -1.0 0.0)) (same_list_float blgs (list 0.0 -1.0 0.0 -1.0)) (same_list_float blgs (list 1.0 0.0 1.0 0.0)) (same_list_float blgs (list 0.0 1.0 0.0 1.0)) ) (progn (setq dst (min (distance (nth 0 pts) (nth 1 pts)) (distance (nth 1 pts) (nth 2 pts)) )) ) ) ;; return distance dst ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:deleteCirclesByDiameter (/ ss diaexception f x tpe) (setq f 0.5000) (setq x globalCleanedValue) (setq ss (ssget "_X" '((0 . "CIRCLE,LWPOLYLINE")))) (princ ss) (setq diaexception '(0.6875 0.6880)) (if ss (progn (princ "*") (prompt (strcat "\nFormatted Value of x: " (rtos x 2 4))) (setq index 0) (repeat (sslength ss) (setq ent (ssname ss index)) ;; we split the tasks. I leave CIRCCLEs alone, ;; but slots, which are polylines get their diameter calculated by the functions above ;; for the rest I don't touch the further handling (setq tpe (cdr (assoc 0 (entget ent)))) (setq dia nil) (if (= tpe "CIRCLE") (setq dia (* 2 (cdr (assoc 40 (entget ent))))) (setq dia (diameter_of_slot ent)) ) (if dia (progn ;; if diameter (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.") ) (prompt "\nNo circles found in the drawing.") ) (princ) ) Quote
ajithkumar.t Posted November 22, 2024 Author Posted November 22, 2024 Hi Emmanuel Delay, above code is working except this c:deleteCirclesByDiameter...it shows, bad argument type: numberp:nil Quote
Recommended Posts
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.