Entity definition lists can also be used to create an entity from scratch. To create an entity, you must define its properties. Supplying an association list or creating the list by asking for information from the user can do this.
Explanation: the (entmake) function
The (entmake) function creates a new entity defined by the list. The data in the list must be association lists and must contain the minimum information required to define the entity. Different entity types require different minimum association lists. If the list contains insufficient information to create an entity, the function returns nil.
- Some information, such as the layer name, is optional. If that information is not supplied in list, the default value is used.
- If a layer name does not exist in the drawing, a new layer is created.
- The entity type (line, arc, circle, etc.) must be listed first in list unless an entity name is supplied. If an entity name is supplied, it must be listed first, followed by the entity type. The entity name is ignored when the entity is created.
Command: (entmake ‘((0 . “line” )(8 . “newlayer”)
(10 1.0 2.0 0.0)(11 2.0 2.0 0.0)))
(defun C:MAKECIRCLE ()
(setq LAYER (getstring “Layer: “))
(setq CENTER (getpoint “Center: “))
(setq RADIUS (getdist cen “Radius: “))
(cons 0 “circle”)
(cons 8 LAYER)
(cons 10 CENTER)
(cons 40 RADIUS)
In this practice you will change the TAG routine so that it uses the (entmake) function to create the objects in your drawing rather than the (command) function. Estimated time for completion: 10 minutes.
Steps to the solution
1. Write up the list of association pairs needed for the line, circle, and text objects. If you do not know the group codes needed, check the DXF Reference Guide (Entities section) in the Help files.
2. Add these as needed to create the objects.
(defun c:TAG ()
Remove (command) functions and add the following:
(entmake (list (cons 0 “line”)
(cons 10 PT1)
(cons 11 LEADERENDPT)))
(entmake (list (cons 0 “circle”)
(cons 10 PT2)
(cons 40 RADIUS)))
(entmake (list (cons 0 “text”)
(cons 72 4)
(cons 10 PT2)
(cons 11 PT2)
(cons 40 (* (getvar “dimscale”) 0.25))
(cons 1 (itoa TAGNUMBER))))
) ;_ end of defun
- The DXF dotted pair code for middle justification is ( 72 . 4) . Text also needs both 10 and 11 set when you are using a justification other than the default.
- A complete solution to this exercise is on your class disk as TAG-D.LSP