Erase all objects within a block using vla-delete

Erase all objects within a block using vla-delete

M2O
Participant Participant
2,025 Views
3 Replies
Message 1 of 4

Erase all objects within a block using vla-delete

M2O
Participant
Participant

I'm looking to erase all objects within a selected block using the (vla-delete) method and then draw a vertical line within the block.

 

Code:

(defun c:EraseAll ()

	(vl-load-com)
	(setq ACAD_Obj (vlax-get-acad-object)
	      ACAD_Doc (vla-get-ActiveDocument ACAD_Obj)
	      ACAD_Blocks (vla-get-Blocks ACAD_Doc)
	)
	
	(setq Block_Selection (vlax-ename->vla-object (car (entsel "\nSelect Block: ")))
	      Block_Name (vla-get-effectivename Block_Selection)
	      Block (vla-item ACAD_Blocks Block_Name)
	)
	
	(vla-delete "Selection Set")
	
	(vla-AddLine Block (vlax-3d-point 0 0 0) (vlax-3d-point 0 50 0))
	(vla-Regen ACAD_Doc acALLViewports)

	(princ)
)

 

This is just a snippet from the actual code and is used as an example of what I'm trying to achieve. Where I'm stuck is what to include in the "Selection Set" to only select the objects within the block.

 

Essentially what trying to accomplish is the equivalent of doing:

(command "-BEDIT" Block_Name
         "_ERASE" "ALL" ""
         "_BCLOSE" "S"
)

 

0 Likes
Accepted solutions (1)
2,026 Views
3 Replies
Replies (3)
Message 2 of 4

ronjonp
Mentor
Mentor
Accepted solution

Add this: 

 

(vlax-for o block (vla-delete o))

Here's a bit of refactoring to validate the block selection:

(defun c:eraseall (/ acad_blocks acad_doc acad_obj block e); <- LOCALIZE VARIABLES
  (if (and (setq e (car (entsel "\nPick a block:"))) (= "INSERT" (cdr (assoc 0 (entget e)))))
    (progn (setq acad_obj    (vlax-get-acad-object)
		 acad_doc    (vla-get-activedocument acad_obj)
		 acad_blocks (vla-get-blocks acad_doc)
		 block	     (vla-item acad_blocks (vla-get-effectivename (vlax-ename->vla-object e)))
	   )
	   (vlax-for o block (vla-delete o))
	   (vla-addline block (vlax-3d-point 0 0 0) (vlax-3d-point 0 50 0))
	   (vla-regen acad_doc acallviewports)
    )
  )
  (princ)
)
(vl-load-com)

 

0 Likes
Message 3 of 4

M2O
Participant
Participant

Awesome, that worked perfectly! Thank you very much! 

0 Likes
Message 4 of 4

ronjonp
Mentor
Mentor

@M2O wrote:

Awesome, that worked perfectly! Thank you very much! 


Glad to help! 👍🏼

0 Likes