
;; ************************************************************************
;;;                I N  T H E   N A M E   O F   G O D
(defun ienlisp ()
 (setvar "cmdecho" 0)
 (setvar "blipmode" 0)
 (setq cl (getvar "clayer"))
 (setq ts (getvar "textstyle"))
 (princ (strcat "\n       * * *   W E L C O M E   T O  < IEN >  P "
                                  "R O G R A M   * * * "))
 (princ (strcat "\nInsert Elevation , Version  1.0 "
                 ", (c) 1995 by R. Negarandeh ."))
  ;;
  ;; Body of function
  ;;
  (if *error*                         ; Set our new error handler
    (setq err_oe *error* *error* err_er)
    (setq *error* err_er)
  )

 (if (= (tblsearch "block" "elev") nil) (makelev))

       (if (= (tblsearch "layer" "elev" ) nil)
           (command "layer" "m" "elev" "c" "1" "" "")
           (command "layer" "s" "elev" "")
       )

 (setq f 0)

 (if
     (= selv1 nil )(setq selv1 (getvar "textsize"))
 )
 (setq selv2 (rtos selv1 2 0))
 (princ (strcat "\nEnter text size <" selv2))
 (setq selv (getreal ">:"))
 (if
     (= selv nil) (setq selv selv1 )
 )
 (setq selv1 selv)

 (if
     (= ielv1 nil )(setq ielv1 0 )
 )
 (setq ielv2 (rtos ielv1 ) )
 (princ (strcat "\nEnter insertion point <X=" ielv2 ))
 (setq ielv (getpoint ">:"))
 (if
     (= ielv nil) (setq ielv ielv1)(setq ielv1 (car ielv))
 )
 (setq ielv ielv1)


 (if
     (= belv1 nil )(setq belv1 0 )
 )
 (setq belv2 (rtos belv1) )
 (princ (strcat "\nSelect base line <Y=" belv2 ))
 (setq basept (entsel ">:"))
    (if (/= nil basept)
       (progn
           (setq e (car basept))
                        (if
                          (= (cdr (assoc 0 (entget e))) "LINE" )
                              (progn
                                 (setq p (cdr (assoc 11 (entget e))))
                                 (setq q (cdr (assoc 10 (entget e))))
                                 (if (= (cadr p) (cadr q))
                                   (setq belv (cadr p))
                                   (progn
                                   (princ "\nEntity isn't a horizontal line !")
                                   (setq f nil)
                                   )
                                 )
                              )
                              (progn
                                     (princ "\nEntity isn't a LINE")
                                     (setq belv belv1)
                                     (setq f nil)
                              )
                        )
       )
       (setq belv belv1)
    )
    (while (/= f nil)
     (progn
      (setq belv1 belv)
      (setq tar (getpoint "\nSelect target point :"))
      (if (/= tar nil)
        (progn
          (setq delta (rtos (* (getvar "dimlfac") (- (cadr tar) belv))))
          (if (= 0 (- (cadr tar) belv))(setq delta (strcat "%%P0" (rtos 0))))
          (setq inspt (list ielv  (cadr tar)))
          (command "insert" "elev" inspt selv "" "0" delta)
        )
        (setq f nil)
      )
     )
    )
      (if err_oe (setq *error* err_oe))   ; Reset old error function if error
 (princ)
 (princ "\n     Good Luck .   ")
 (setvar "blipmode" 1)
 (setvar "cmdecho" 1)
 (setvar "clayer" cl)
 (setvar "textstyle" ts)
 (prin1 )
)

(defun makelev ()
 (setvar "clayer" "0")
 (setq basep (list 0 0 0))

       (if (= (tblsearch "style" "elev" ) nil)
           (command "style" "elev" "simplex" "" "" "10" "" "" "")
           (setvar "textstyle" "elev" )
       )

          (setq ssblock (ssadd))
          (command "line" "-0.5,0" "0.5,0" "")
          (ssadd (entlast) ssblock)
          (command "line" "0.0,0.0" "-1.0,0.5" "")
          (ssadd (entlast) ssblock)
          (command "line" "-1.0,0.5" "1.0,0.5" "")
          (ssadd (entlast) ssblock)
          (command "line" "1.0,0.5" "0.0,0.0" "")
          (ssadd (entlast) ssblock)
          (command "line" "-1.0,.75" "6.5,.75" "" )
          (ssadd (entlast) ssblock)
   (command "attdef" "" "00.00" "" ""  "j" "br" "6.5,.75" "1" "")
   (ssadd (entlast) ssblock)
   (command "block" "elev" basep ssblock "")
)
(setq ienid 1)
(defun c:IEN () (ienlisp) )
 (prin1)

(princ (strcat "\n      <Insert "
                         "Elevation> loaded.  Start command with IEN ." ))
(princ )
