Delete Blok inside attribute

Delete Blok inside attribute

bahaatawfiq
Participant Participant
396 Views
4 Replies
Message 1 of 5

Delete Blok inside attribute

bahaatawfiq
Participant
Participant

hi every I have arch Plan and thy made hatch inside furniture ,grid  and Tags I found lisp Which Delete hatch  from all drawings but I need update it to delete hatch only from selected item because I need to keep wall hatch 

 

(defun c:Test (/ doc)
 (vlax-for bks (vla-get-blocks (setq
                     doc (vla-get-ActiveDocument (vlax-get-acad-object))
                   )
                 )
   (if (and (eq :vlax-false (vla-get-islayout bks))
            (eq :vlax-false (vla-get-isXref bks))
       )
     (vlax-for obj bks
       (if (and (wcmatch (vla-get-objectname obj)
                         "AcDbHatch"
                )
                (vlax-write-enabled-p obj)
           )
         (vla-delete obj)
       )
     )
   )
 )
 (vla-regen doc AcAllViewports)
 (princ)
)(vl-load-com)

 can any one help with this  

0 Likes
397 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

Try this

 

(defun c:Test (/ blks ent bks blks obj)
(setq blks (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
(while (setq ent (entsel "\nPick a block Enter to exit "))
  (setq bname (cdr (assoc 2 (entget (car ent)))))
  (vlax-for bks blks
   (if (and (eq :vlax-false (vla-get-islayout bks))
            (eq :vlax-false (vla-get-isXref bks))
			(eq (vla-get-name bks) bname)
       )	   
     (vlax-for obj bks
       (if (and (wcmatch (vla-get-objectname obj)
                         "AcDbHatch"
                )
                (vlax-write-enabled-p obj)
           )
         (vla-delete obj)
       )
     )
   )
  )
)
 (vla-regen doc AcAllViewports)
 (princ)
)(vl-load-com)
0 Likes
Message 3 of 5

bahaatawfiq
Participant
Participant

Unfortunately not worked, I get error "Pick a block Enter to exit ; error: bad argument type: VLA-OBJECT nil" as sample i need to delete the solid hatch from the grid and window and door tags .that sample project i have project with huge number of same issue 

0 Likes
Message 4 of 5

john.uhden
Mentor
Mentor

@bahaatawfiq 

Those Aussies tend to skip over things.

Change

(while (setq ent (entsel "\nPick a block Enter to exit "))

to

(while (setq ent (car (entsel "\nPick a block, Enter to exit: ")))

 

John F. Uhden

0 Likes
Message 5 of 5

ronjonp
Advisor
Advisor

@Sea-Haven 

No need to iterate all the blocks in the drawing if you're picking them ?

 

(defun c:test (/ blks bname ent)
  (setq blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
  (while (and (setq ent (car (entsel "\nPick a block Enter to exit ")))
	      (setq bname (cdr (assoc 2 (entget ent))))
	      (tblobjname "BLOCK" bname)
	 )
    (vlax-for obj (vla-item blks bname)
      (if (wcmatch (vla-get-objectname obj) "AcDbHatch")
	(vl-catch-all-apply 'vla-delete (list obj))
      )
    )
  )
  (princ)
)
(vl-load-com)

 

 

 

 

 

 

0 Likes