Erase Block

Erase Block

townest
Advocate Advocate
1,186 Views
5 Replies
Message 1 of 6

Erase Block

townest
Advocate
Advocate

I searched around and found the following lisp to erase a named block:

(command "erase" (SSGET "X" '((0 . "INSERT") (2 . "Part1" ))) "")

where Part1 is the block name.

 

It works, but I want to understand it better.  What is the insert, if I'm trying to erase.  Can someone break it down term by term so I can understand it better?  Thank you.  Tyler

0 Likes
Accepted solutions (1)
1,187 Views
5 Replies
Replies (5)
Message 2 of 6

Jonathan3891
Advisor
Advisor

"INSERT" is a block.

This is called a selection set filter and the "Insert" I believe is called the object type.

 

The object type can be many things or a combination of things.


For example you can search for a "LINE" that's Linetype "DASHED" and Color 2

(setq ss (ssget "X" '((6 . "DASHED")(62 . 2))))


Each part of the filter contains DXF codes for linetype, color, etc.


http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-3F0380A5-1C15-464D-BC66-2C5F094BCFB9 

 


Jonathan Norton
Blog | Linkedin
0 Likes
Message 3 of 6

SeeMSixty7
Advisor
Advisor

The "INSERT" is for the DXF 0 code which is the type of entity it is. "INSER" means it is a BLOCK INSERT.

DXF code 2 is for the name of the block

Other DXF codes can me used to isolate even further.

DXF 8 is for layer

DXF  40 41 and 43 are the XY&Z scales of the insert

 

Different entities have different codes. Some are common.

0 will always be there and is the ent type

2 is only there for blocks and attribute definitions.

8 is always there as all entities have a layer.

etc.

 

You can do a search for DXF Codes and find a pretty good reference for them.

 

You can also query any entity to look at it's dxf codes by using something like this.

(entget (car (entsel "\nSelect Entity:")))

That will return quite a bit of information for you to look at.

 

Good luck,

0 Likes
Message 4 of 6

ronjonp
Mentor
Mentor

You can use this to look into what dxf codes make an entity:

(defun c:dxflist (/ e)
  (cond	((setq e (car (entsel "\nPick something to see DXF data: ")))
	 (mapcar 'print (entget e '("*")))
	 (textscr)
	)
  )
  (princ)
)
0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

A few additional comments....

 

The (ssget) function is to get a selection set.  The "X" in it is the selection mode, which has it look at the entire drawing -- without that, the User will be asked to select objects.  In either case, (ssget) will "see" only those things among the selection that fit the criteria in the filter list.  With the "X", it finds qualifying things in the entire drawing including Model Space and all Layouts of Paper Space, but in a (command) function calling a command involving object selection [such as ERASE in your example], it will apply the command to only those in the current space.  If you want them removed from Model Space and multiple Layouts, that can be done, but not with an ERASE command in a (command) function -- it would need to step through the selection set and use (entdel) on all the Blocks found.

 

The "INSERT" entity type also finds XREFs [and WMFs, in case you ever use those].  In this case, it wouldn't be likely to ERASE any of those you don't want it to, because presumably none would fit the name  filter.

 

The apostrophe ' before the double left parenthesis is shorthand for the (quote) function, and the left parenthesis immediately after it begins a list [in this case the filter list for selection] -- read about (quote) and its relation to the (list) function in the AutoLisp Reference.

 

The double double-quote "" near the end is an empty text string, which means Enter, and which completes the object selection in the ERASE command, and therefore finishes the command.

Kent Cooper, AIA
0 Likes
Message 6 of 6

ronjonp
Mentor
Mentor

@Kent1Cooper wrote:

A few additional comments....

 

....

 

If you want them removed from Model Space and multiple Layouts, that can be done, but not with an ERASE command in a (command) function -- it would need to step through the selection set and use (entdel) on all the Blocks found.

 

...


@Kent1Cooper 

FWIW .. using entdel does not work on all layouts. I found this out when trying to be clever using:

(mapcar 'entdel listofenames)

I had to convert them to VLA objects and use vla-delete for it to work on all layouts.

0 Likes