Jump to content

Delete duplicate block


Recommended Posts

Posted (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 by sivapathasunderam
Posted

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)
    )

 

  • Thanks 1
Posted (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 by sivapathasunderam
Posted

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)
    )

 

  • Like 2
Posted (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 by mhupp
  • Thanks 2

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...