ENTMAKE-ing Blocks from an AutoLISP program

User functions col_def, niv_def y alt_def use the entmake functionto generate Blocks that include graphic objects and both visible and invisibletext attributes. To use this program you may download it from the Attached document link at the bottom of this page. Save the file with the name BLK-DEF.LSP  in a directory that figures in the ACAD environment variable(for instance, SUPPORT). To inspect the contents of this variable type in the command line (getenv "ACAD"). To load it type (load "BLK-DEF")

Reinaldo Togores. Associate Professor.
Departamento de Ingeniería Geográfica y Técnicas deExpresión Gráfica
Universidad de Cantabria.Diciembre de 1996.
Use of the code in these programs ishereby authorized, with the condition that due credit is given to the author.
Mail yor comments and suggestions to:reinaldo.togores@unican.es

Definition of Block NIV_ID

This block includes a POINT marker and a visible text attribute and will be used to annotate terrain heights.





(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 . "Columna Num.")(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" ))


Reinaldo Togores Fernández,
28 mar 2011, 15:35
v.2