@Ranjit_Singh wrote:
I agree with @cadffm. I cannot possibly think of any function where you would want the repeat loop to follow a certain sequence. If the entity is a simple entity then you can use entmakex below to create a new one.
(entmakex (entget entityename))
This creates a new entity which should now be entlast. Then you can delete old one
(entdel entityename)
Trying to copy an entity via (entmake (entget/x ...)) is what led to millions of corrupt drawing files (with the infamous "multiply-owned object" errors that are detected by AUDIT). If ignored, the drawing eventually becomes partially or entirely unrecoverable.
You cannot copy an entity via that means, for at least three major reasons. First, if the entity being copied has an extension dictionary, the extension dictionary is a separate object unto itself, which does not get copied when you copy the entity that owns it using entget/entmake. So, the result of (entmake (entgetx ...)) on an object with an extension dictionary is two entities that both own the same extension dictionary, which means the drawing is corrupt, and will only get worse if it is ignored.
Second, attempting to copy an entity using entget+entmake does not always produce an exact copy. For example, a non-existent color in the result of (entget) means the entity's color is BYLAYER. If you pass that same list unmodified to (entmake) without a color group, (entmake) interprets that to mean use the current value of CECOLOR , not BYLAYER. Ditto for linetypes, etc.
Thirdly, many custom objects from AutoCAD verticals do not fully-support (entmake) and do not always render a complete representation of themselves via (entmake). Entget and Entmake are essentially a way to do a DXFOUT and DXFIN, on an object-by-object basis. Custom objects from verticals do not support DXF any longer, so trying to copy them using entget+entmake may not always be possible.
You can use vla-Copy or vla-CopyObjects (or the COPY command) to correctly and safely copy one or more entities.
There are various other problems that will result from trying to do your own draworder by copying and deleting. For example, we have what are known as "inter-object references", which is where one or more entities have a reference to another object stored in their data (or their extension dictionary). A familiar example is a field that references the area of a polyline or other closed curved. The field object (which is in an extension dictionary that would not be copied by entget/entmake) holds a reference to the polyline whose area it displays. When you try to copy the polyline and delete the original, the field now references a deleted object. That would not happen if you used the COPY command, or vla-CopyObjects, and both the field and the polyline it references were copied together. In that case, the resulting copy of the field will reference the resulting copy of the polyline.
That's just a few of many problems with trying to use entgetx and entmake to copy objects, and copying and erasing to establish draw-order. If possible, use AutoCAD's DRAWORDER functionality, since you're paying the price for it (in terms of performance) anyways.