sivapathasunderam Posted February 9, 2023 Posted February 9, 2023 (edited) I can't able a delete the duplicate block above on it (Need to delete the block which is not having elevation text as attribute) I try overkill also not works I have attached cad dwg Ask forum.dwg Edited February 9, 2023 by sivapathasunderam Quote
hosneyalaa Posted February 9, 2023 Posted February 9, 2023 HI TRY (defun c:deleteC ( / E I SS) (if (setq ss (ssget '((0 . "INSERT")))) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (if (= (vlax-invoke e 'GetAttributes) nil) (vla-delete e) ) ) ) (princ) ) 1 Quote
sivapathasunderam Posted February 9, 2023 Author Posted February 9, 2023 (edited) 3 hours ago, hosneyalaa said: HI TRY I want to add this line (princ (strcat "\nTotal of " (itoa (sslength e)) " Object(s) were deleted ... " )) Edited February 9, 2023 by sivapathasunderam Quote
hosneyalaa Posted February 9, 2023 Posted February 9, 2023 TRY (defun c:deleteC ( / E I SS) (if (setq ss (ssget '((0 . "INSERT")))) (progn (setq n 0) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (if (= (vlax-invoke e 'GetAttributes) nil) (progn (setq n (+ 1 n)) (vla-delete e) ) ) ) ) ) (princ (strcat "\nTotal of " (itoa n) " Object(s) were deleted ... " )) (princ) ) 2 Quote
mhupp Posted February 9, 2023 Posted February 9, 2023 (edited) You already had it @hosneyalaa no need for a counter. (princ (strcat "\nTotal of " (itoa i) " Object(s) were deleted ... " )) You can select blocks that don't have attributes directly with ssget (66 . 0) so you then don't have to test for attributes and just delete everything in the selection set. ;;----------------------------------------------------------------------------;; ; DELETE SELECTED BLOCK THAT DON'T HAVE ATTRIBUES (defun c:deleteC (/ e i ss) (setq ent (car (entsel "\nSelect Block"))) (setq blkname (cdr (assoc 2 (entget ent)))) (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname) '(66 . 0)))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (entdel ent) ) (princ (strcat "\n0 " blkname " Block(s) Deleted ... ")) ) (if ss (princ (strcat "\n" (itoa (sslength ss)) " " blkname " Block(s) Deleted ... ")) ) (princ) ) Edited February 9, 2023 by mhupp 2 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.