Alright, please try the following program and let me know how you get on with it.
Be sure to have the current layer unlocked although I can alert message to the user for this issue if you would like to.
Code:
(defun c:Test (/ *error* var sel blk ins pth)
;; Tharwat - 24.Oct.2019 ;;
(defun *error* (msg)
(and var (mapcar 'setvar '(ATTREQ ATTDIA) var))
(and *doc* (vla-regen *doc* AcActiveviewport))
(and msg
(not (wcmatch (strcase msg) "*CANCEL*,*EXIT*,*BREAK*"))
(princ (strcat "\nError =>: " msg))
)
(princ)
)
(and
(or (findfile (setq pth
"U:\\MANUALS\\CIVIL_QLD\\CAD\ Standard\ Data\\Stormwater\\Blocks\\Catchment Label1.dwg"
)
)
(alert "Path of block is uncorrect <!>")
)
(or *doc*
(setq *doc* (vla-get-ActiveDocument (vlax-get-acad-object)))
)
(or
(tblsearch "BLOCK" "CATCHMENT LABEL1")
(and (setq blk (vlax-invoke
(vla-get-modelspace *doc*)
'insertblock
'(0. 0. 0.)
pth
1.
1.
1.
0.
)
)
(progn (vla-delete blk)
(tblsearch "BLOCK" "CATCHMENT LABEL1")
)
)
(alert
"Block name <CATCHMENT Label1> not found in original drawing <!>"
)
)
(or *initdgt* (setq *initdgt* 1))
(or (initget 6)
(setq
*initdgt* (cond ((getint (strcat "\nSpecify start number < "
(itoa *initdgt*)
" > : "
)
)
)
(*initdgt*)
)
)
)
(setq var (mapcar 'getvar '(ATTREQ ATTDIA)))
(mapcar 'setvar '(ATTREQ ATTDIA) '(0 0))
)
(while (and (princ "\nPick a closed polyline : ")
(setq sel (ssget "_+.:S:E" '((0 . "LWPOLYLINE"))))
)
(and
(or (= (cdr (assoc 70 (entget (ssname sel 0)))) 1)
(alert "Picked polyline is opened!. Try again.")
)
(setq
ins (getpoint "\nSpecify attributed block insertion point : ")
)
(setq blk (vlax-invoke
(vla-get-modelspace *doc*)
'insertblock
ins
"CATCHMENT LABEL1"
1.
1.
1.
0.
)
)
(mapcar
'(lambda (at)
(vla-put-textstring
at
(if (= (vla-get-tagstring at) "NAME")
(strcat "C" (itoa *initdgt*))
(strcat "%<\\AcObjProp Object(%<\\_ObjId "
(get:id (vlax-ename->vla-object (ssname sel 0)))
">%).Area \\f \"%lu6%qf1%ps[,ha]%ct8[0.0001]\">%"
)
)
)
)
(vlax-invoke blk 'getattributes)
)
(setq *initdgt* (1+ *initdgt*))
)
)
(*error* nil)
(princ)
) (vl-load-com)
;; ;;
(defun get:id (o / u)
(if (vlax-method-applicable-p
(setq u (vla-get-Utility *doc*))
'GetObjectIdString
)
(vla-GetObjectIdString u o :vlax-false)
(itoa (vla-get-ObjectId o))
)
)