Use AutoLisp to remove an AutoCAD-specific entity within a specified layer

Source: Internet
Author: User
Tags error handling

How do I get a layer name for straight and multi-line lines in CAD graphics files with AutoLisp?

Use (CDR (Assoc 8 (Entget (Entsel))) to get the layer name of the line and other entities.

The program you want is to point to a line, get the layer name of the line, and then change the line width of all the lines in that layer to a value. What I want now is the step of "point to line, get the layer name".

(Setq Lyname (CDR (Assoc 8 (Entget (Entsel)))) That's it!, What else D

(Setq Lyname (CDR (Assoc 8 (Entget (Entsel)))) That's it!, What else do you want?

This is often the case in the drawing process: a layer has been "emptied" but cannot be deleted. In fact, layers may also contain entities that are not visible. For example, you use the Mtext command to enter a series of spaces, which produces an invisible entity. In the actual drawing, of course, we do not deliberately to establish such an entity, but the unintentional operation or ACAD application operation is likely to produce a "by-product", to remove these invisible entities, if the Acad command is difficult to complete, must use the program to do, The following program can remove all the simple entities within the specified layer, allowing the user to further use the layer or purge command to remove the layer.

It is to be noted that individual layers may be associated with other objects even after they are processed by using the following program (note that the concept of the object is much larger than the entity, including the callout style, and not entity objects) and cannot be deleted unless the specified layer is no longer associated with the tile or does not contain any user-defined callout styles. These layers are:

1. A layer defined by a block, such as a layer containing a tile, a line within the block is a B-layer;

2. A special layer with the name defpoints (used for a callout style).

The list of procedures is as follows:

(Defun c:de (/et ln lay_name SS Li)

(princ "Delete entity n in the specified layer")

(setq li (entsel "n Please select any entity within the specified layer < Enter a direct input layer name:")

(If Li

(PROGN; Select an entity

(Setq et (Entget (nth 0 li))

(Setq Lay_name (CDR (Assoc 8 ET))

)

(PROGN; Directly enter the layer name, the ideal way is to use the list box selection, you can try.

(princ "Input layer name:")

(while (= ln nil)

(setq lay_name (getstring))

(SETQ ln (CDR (Assoc 2 (tblnext "layer" T)))

(while (/= ln "%"))

(if (/= ln lay_name)

(SETQ ln (CDR (Assoc 2 (tblnext "layer")))

(SETQ ln "%")

If the specified layer name already exists, set the% flag

)

)

(if (/= ln "%"); error handling

(princ "The specified layer does not exist, please re-enter:")

)

)

)

)

(setq SS (Ssget "X" (List (cons 8 lay_name)));

(COMMAND "-layer" "U" Lay_name ""); layer unlock

(COMMAND "ERASE" "ss"); Clear all entities

(princ "N purge complete!")

(Princ)

)

; End of program

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.