Code:
(defun attsurf (bname / acadobj aecapp aecProj aecsurfs aecsurf aecutil e-n
emsg pt# selev appstr versn *error* att blk space)
(defun *error* (msg / objlist)
(setq objList
(reverse
(list acadobj aecapp aecProj aecsurfs aecsurf aecutil)
)
)
(vl-catch-all-apply
'(lambda ()
(mapcar 'vlax-release-object objlist)
)
)
(if msg
(princ (strcat "\n" msg))
)
(princ)
)
;;;;;
(setq appstr (cond ((= (setq versn (atoi (substr (getvar "acadver") 1 2))) 15) "2")
((= versn 16) "4")
((= versn 17) "6")
)
)
(setq acadObj (vlax-get-acad-object)
space (vla-get-modelspace (vla-get-activedocument acadObj))
aecApp (vla-getinterfaceobject acadObj (strcat "Aecc.Application." appstr))
aecProj (vlax-get aecApp "Activeproject")
aecSurfs (vlax-get aecProj "Surfaces")
aecSurf (vlax-get aecSurfs "Currentsurface")
aecUtil (vlax-get (vlax-get aecApp "activedocument") "Utility")
)
(if (and (= aecSurf "")
(> (vlax-get aecSurfs "count") 0)
)
(setq aecSurf (vlax-get (vlax-invoke aecSurfs "item" 0) "name"))
)
(if (= aecSurf "")
(princ
"\nNo surfaces defined, try again after creating a surface."
)
(progn
(setq aecSurf (vlax-invoke aecSurfs "item" aecSurf))
(while (setq
pt# (getpoint "\nPoint to label on the current surface: ")
)
(setq e-n (vlax-invoke aecutil "xytoeastnorth" pt#))
(setq selev (vlax-invoke
aecSurf
"getelevation"
(car e-n)
(cadr e-n)
)
)
;;Insert your block insertion and attribute setting here
(setq blk (vlax-invoke space 'insertblock pt# bname 1.0 1.0 1.0 0.0))
(setq att (car (vlax-invoke blk 'getattributes)))
(vla-put-textstring att (rtos selev 2 2))
;(princ (strcat "\nElevation at point = " (rtos selev)))
)
)
)
(*error* nil)
)
;;;make as many of these as you need, this is for the SPOTL40 block
(defun c:SPOTL (/ bname)
(setq bname "sptl40");;set the block name in this line
(if (or (tblsearch "BLOCK" bname)
(setq bname (findfile bname))
)
(attsurf bname)
)
(princ)
)