Fandom

AutoCAD

Entmaking block definitions

45pages on
this wiki
Add New Page
Talk0 Share

Why entmake block definitionsEdit

The portability of programs that insert blocks is limited by the need to include, with the program, the required block libraries. This forces the programmer to package the drawings with the code, implementing some kind of batch procedure to help in its installation. The user must take care of setting the required environment variables that insure that the program will find the required drawings. Of course, a change in the structure of directories will render that program useless if the pertinent corrections aren't made to the ACAD paths. The same is valid for changes in file names. Uniformity in the operation of the program is not assured, as the drawings may be subject to tampering by anyone.

A way to overcome these difficulties is to define each time the required blocks, by means of the same program's code. This can be attained in a very efficient way by using the entmake function which creates, through direct access to the drawing's data base, the required new entities. The entmake function is specially adequate to the definition of blocks without the need of previously drawing the component entities. The resulting blocks may contain any valid drawing entity, including text attributes.

How to entmake blocksEdit

This function's syntax is as follows:

   (entmake [entity_list])

where [entity_list] contains the information which is neccessary to the creation of the desired entity in formatted in a way which is similar to that which the function entget returns. A simple way in which the programmer can obtain this list consists in previously drawing the required objects, and then using entget -typing, for instance (entget (car (entsel)))- and copying the resulting entity list. Copying may be done by selecting the text directly from the text window if you are using release 13 for WINDOWS, or implemented, for DOS users through a simple routine that writes the resulting code to a text file.

Blocks and other complex entities (such as POLYLINES) must be created through several successive calls to the entmake function that define, one by one, their components (vertex, attributes, etc.). When entmake detects the creation of a complex entity, a temporary file is opened, in which the definition's data are stored. Each time entmake is used, the existence of this temporary file is checked and the new information is included. Once the complex entity's definition is concluded, (through the creation of the neccessary SEQEND or ENDBLK entities, according to the type of complex entity definition) data is validated and if it is correct, the entity is added to the drawing's data base. If it succeeds in creating the entity, entmake returns the entity list or, if it is a block, its name. If entmake fails then nil is returned.

To avoid redefining an existing block, if one with the same name already exists, it is advisable to previously explore the blocks table using the tblsearch function.

Entmake can also be used in creating NON-GRAPHICAL objects, such as layers, dimstyles etc.

ENTMAKE-ing Blocks from an AutoLISP programEdit

User functions col_def, niv_def y alt_def use the entmake function to generate Blocks that include graphic objects and both visible and invisible text attributes.

To use the following code, select it in your browser from the "-PROGRAM BEGINS HERE-"to the "-PROGRAM ENDS HERE-" line, copy the selected text (Ctrl+C), open an editor (Notepad o Visual LISP) and paste it there (Ctrl+V). Save the file thus created with the name LISTENT.LSP in a directory that figures in the ACAD environment variable (for instance, SUPPORT). To load it type (load "listent")

Written By Reinaldo Togores. Associate Professor.

Departamento de Ingeniería Geográfica y Técnicas de Expresión Gráfica

Universidad de Cantabria. Diciembre de 1996.

Use of the code in these programs is subject to the terms of the GNU General Public License.

;;;----------------------PROGRAM BEGINS HERE-------------------------------------------------
;;Definition of Block NIV_ID
;;(c)Reinaldo Togores. Santander, 1997.
;;This block includes a POINT marker and a visible text attribute and 
;;will be used to annotate ground levels
(defun niv_def ()
  
  ;BLOCK Header definition:
  
  (entmake '((0 . "BLOCK")(2 . "NIV_ID")(70 . 2)(10 0.0 0.0 0.0)))
  
  ;POINT marker definition:
  
  (entmake '((0 . "POINT")(8 . "0")(10 0.0 0.0 0.0)(210 0.0 0.0 1.0)(50 . 0.0)))
  
  ;Text ATTRIBUTE definition:
  
  (entmake 
    '((0 . "ATTDEF")(8 . "0")(10 4.0 -2.0 0.0)(1 . "")(2 . "COT_NIV")
    (3 . "Cota de Nivel")(40 . 4.0)(41 . 1.0)(50 . 0.0)(70 . 0)(71 . 0)(72 . 0)(73 . 2))
  )
  
  ;BLOCK's ending definition:
  
  (entmake '((0 . "ENDBLK")))
  
)
;;Definition of Block ALT_ID
;;This Block only contains a visible text attribute. It will be used to annotate
;;building Heights in a cadastral map.
(defun alt_def ()
  
  ;BLOCK Header definition:
  ;Code 70 shows that attributes follow. Code 10 contains the
  ;insertion point.
  
  (entmake '((0 . "BLOCK")(2 . "ALT_ID")(70 . 2)(10 0.0 0.0 0.0)))
  
  ;Text ATTRIBUTE definition:
  
  (entmake 
    '((0 . "ATTDEF")(8 . "0")(10 0.0 0.0 0.0)(1 . "I")(2 . "NUM_ALT")
    (3 . "Alturas")(40 . 2.0)(41 . 1.0)(50 . 0.0)(70 . 0)(71 . 0)(72 . 4)(73 . 2))
  )
  
  ;BLOCK's ending definition:
  
  (entmake '((0 . "ENDBLK")))
)
;;Definition of Block COL_SIM. This Block will represent the high tension
;;electrical supply towers. This function is invoked from the C:COL program
;;that inserts the symbols in case that they haven't been previously defined.
(defun col_def ()
  
  ;BLOCK Header definition:
  
  (entmake '((0 . "BLOCK")(2 . "COL_SIM")(70 . 2)(10 0.0 0.0 0.0)))
  
  ;POLYLINE Header definition:
  ;Note that it is a closed POLYLINE (code 70=1)
  
  (entmake 
    '((0 . "POLYLINE")(8 . "0")(66 . 1)(10 0.0 0.0 0.0)(70 . 1)(40 . 0.0)
    (41 . 0.0)(210 0.0 0.0 1.0)(71 . 0)(72 . 0)(73 . 0)(74 . 0)(75 . 0))
  )
  
  ;Multiple VERTEX definition:
  
  (entmake 
    '((0 . "VERTEX")(8 . "0")(10 -2.0 -2.0 0.0)(40 . 0.0)(41 . 0.0) 
    (42 . 0.0)(70 . 0)(50 . 0.0)(71 . 0)(72 . 0)(73 . 0)(74 . 0))
  )
  
  (entmake
    '((0 . "VERTEX")(8 . "0")(10 -2.0 2.0 0.0)(40 . 0.0)(41 . 0.0)
    (42 . 0.0)(70 . 0)(50 . 0.0)(71 . 0)(72 . 0)(73 . 0)(74 . 0))
  )
  
  (entmake
    '((0 . "VERTEX")(8 . "0")(10 2.0 2.0 0.0)(40 . 0.0)(41 . 0.0)
    (42 . 0.0)(70 . 0)(50 . 0.0)(71 . 0)(72 . 0)(73 . 0)(74 . 0))
  )
  
  (entmake
    '((0 . "VERTEX")(8 . "0")(10 2.0 -2.0 0.0)(40 . 0.0)(41 . 0.0)
    (42 . 0.0)(70 . 0)(50 . 0.0)(71 . 0)(72 . 0)(73 . 0)(74 . 0))
  )
  
  ;POLYLINE sequence ending definition:
  
  (entmake '((0 . "SEQEND")))
  
  ;Diagonal LINE definition:
  
  (entmake
    '((0 . "LINE")(8 . "0")(10 -2.0 2.0 0.0)(11 2.0 -2.0 0.0)(210 0.0 0.0 1.0))
  )
  
  ;The other diagonal LINE:
  
  (entmake
    '((0 . "LINE")(8 . "0")(10 -2.0 -2.0 0.0)(11 2.0 2.0 0.0)(210 0.0 0.0 1.0))
  )
  
  ;Text ATTRIBUTE definition:
  ;Note that it is an invisible attribute (code 70=1)
  
  (entmake 
    '((0 . "ATTDEF")(8 . "0")(10 -2.0 -8.0 0.0)(1 . "00")(2 . "COL_ID")
    (3 . "Column #.")(40 . 4.0)(41 . 1.0)(50 . 0.0)(70 . 1)(71 . 0)(72 . 0)(73 . 0))
  )
  
  ;BLOCK's ending definition:
  
  (entmake '((0 . "ENDBLK")))
  
)
;;;--------INSERTION PROGRAMS-----------------------------------------------------------
;;Program that inserts terrain levels:
(defun C:NIV ()   
  (setq oce (getvar "cmdecho"))(setvar "cmdecho" 0)   
  (setq oad (getvar "attdia"))(setvar "attdia" 0)
  (setvar "luprec" 2)(setvar "pdmode" 0)
  
  ;If NIV_ID Block definition doesn't existe, then entmake-it:
  (if (null (tblsearch "BLOCK" "NIV_ID"))(niv_def))
  
  (command "_layer" "_make" "nivel" "_color" "7" "nivel" "")
  
  ;Begins the level insertion cycle. Previous value is taken as default
  ;value (OLDNIV variable).
  (if (null oldniv)(setq oldniv "0.0"))
  (while (setq ptniv (getpoint "\nPlace LEVEL: "))
    (setq txniv (getstring (strcat "\nTerrain Level <" oldniv "> : ")))
    (if (= txniv "")(setq txniv oldniv)(setq oldniv txniv))
    (command "insert" "niv_id" ptniv 1 1 0 txniv)
  )
  (setvar "attdia" oad)(setvar "cmdecho" 1)
)
;;Program that inserts building height annotation:
(defun C:ALT ( / oce oad ptalt txalt )   
  (setq oce (getvar "cmdecho"))(setvar "cmdecho" 0)   
  (setq oad (getvar "attdia"))(setvar "attdia" 0)
  (setvar "luprec" 2)(setvar "pdmode" 0)
  (if (null (tblsearch "BLOCK" "ALT_ID"))(alt_def))
  (command "_layer" "_make" "bldg_heights" "_color" "1" "bldg_heights" "")
  (if (null oldalt)(setq oldalt "I"))
  (while (setq ptalt (getpoint "\nSelect Building: "))
    (setq txalt (getstring (strcat "\n# Floors <" oldalt ">: ")))
    (if (= txalt "")(setq txalt oldalt)(setq oldalt txalt))
    (command "insert" "alt_id" ptalt 1 1 0 txalt)
  )(setvar "attdia" oad)(setvar "cmdecho" oce)
)
;;High Tension Towers insertion Program (block COL_ID)
;;Setting the initial counter number:
(defun nxtcol ( / )
  (if 
    (null (setq cnt_col (getint "\nNext TOWER #: ")))
    (setq cnt_col 0)
  )
)
;;Main Program:
(defun C:COL ( / oce col1 col2 prang)   
  (setq oce (getvar "cmdecho"))(setvar "cmdecho" 0)   
  
  ;If COL_ID Block definition doesn't existe, then entmake-it:
  
  (if (null (tblsearch "BLOCK" "COL_SIM"))(col_def))
  (if (null cnt_col)(nxtcol)(setq cnt_col (1+ cnt_col)))
  
  ;The following lines allow for the selection of a color if the current entity color
  ;is BYLAYER or BYBLOCK. The selected color is used in making a new layer
  ;into which the symbols will be inserted.
  
  (setq ncolor
    (if (=(type (read (getvar "cecolor"))) 'INT)
      (getvar "cecolor")
      (acad_colordlg 1 nil)
    )
  )
  
  ;The insertion cycle begins here, towers are sequentially numbered and rotated 
  ;according to the angle to the previous and succeeding towers.
  
  (if (setq col1 (getpoint (strcat "\nPlace TOWER " (itoa  (setq cnt_col (1+ cnt_col))) ": ")))
    (progn
      (command "_layer" "_make" "el_towers" "_color" ncolor "el_towers" "")
      (initget 33)
      (while (setq col2 (getpoint col1 (strcat "\nPlace TOWER " (itoa (1+ cnt_col)) ": ")))
        (command "insert" "col_sim" col1 1 1 
          (if prang
            (/ (* (/ (+ prang (angle col1 col2)) 2) 180.0) pi)
            (/ (* (setq prang (angle col1 col2)) 180.0) pi)
          )
          (itoa cnt_col)
        )
        (setq prang (angle col1 col2) col1 col2 cnt_col (1+ cnt_col))(initget 32)
      )
      (command "insert" "col_sim" col1 1 1 (/ (* prang 180.0) pi)(itoa (1+ cnt_col)))
    )
  )
  (redraw)(setvar "cmdecho" oce)
)
;;Dialog that shows Program Names on loading:
(alert 
  (strcat
    "LOADED PROGRAMS:"
    "\nCOL=Inserts TOWERS"
    "\nNIV=LEVEL Annotations"
    "\nALT=Building Heights"    
  )
)
;;;----------------------PROGRAM ENDS HERE-------------------------------------------------

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.