Hi Christian, good...
yes, it will work but for new blocks only. If you want to keep the functionality for the both old and new blocks, you need something smarter. The following suggestion will cover it, but again, old and new block only (no other additional formatting). I think it should be enought for you... but all-covering solution would be use some StripMtext function...
Anyway, I've also added the leading-zeros recognition... I guess you may find it useful. Now it is automated, but you might uncomment user prompt if you find it necessary.
Most changes is bold.
(vl-load-com)
(defun c:<Koordpunkt ( / *error* lay cmd :MaxAttValue :AddLeadingZeros txt enl enlast)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg)))
(setvar 'CLAYER lay)
(princ "\nLetzte Punktnummer gespeichert!")
(terpri)
(princ))
(defun :MaxAttValue (pre / mxm i en em val att frm)
(setq mxm "0")
(if (setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "SPI-Koordinatenpunkt") (cons 410 (getvar 'CTAB)))))
(repeat (setq i (sslength ss))
(setq en (ssname ss (setq i (1- i))))
(while (/= (cdr (assoc 0 (setq em (entget (setq en (entnext en)))))) "SEQEND")
(and (eq (cdr (assoc 0 em)) "ATTRIB")
(setq att (cdr (assoc 1 (reverse em))))
(setq frm (cond ((vl-string-search pre att))
((vl-string-search ";" att))))
(setq val (substr att (+ 1 frm (strlen pre))))
(> (atoi val) (atoi mxm))
(setq mxm val)
))))
mxm)
(defun :AddLeadingZeros (a d / b) ;add zeros to 'd' many digits ;a string
(strcat (substr "000000000" 1 (if (>= d (setq b (strlen (itoa (fix (atof a)))))) (- d b) 0)) a))
; ------------------------------------------------------------------------------------------------------
(setq lay (getvar 'CLAYER))
(command "_.-LAYER" "_m" "-I-Koordinatenpunkte" "_co" "3" "-I-Koordinatenpunkte" "")
(setq oATTREQ (getvar 'ATTREQ)
oATTDIA (getvar 'ATTDIA))
(setvar 'ATTREQ 1)
(setvar 'ATTDIA 0)
(or *<Koordpunkt-g*
(setq *<Koordpunkt-g* ""))
(initget 128)
(setq *<Koordpunkt-g* (strcase (cond ((getkword (strcat "\nGeschoss angeben (zB. \"1U-\", \"EG-\" oder \"\" für Ohne) <" (if (= "" *<Koordpunkt-g*) "Ohne" *<Koordpunkt-g*) ">: ")))
(*<Koordpunkt-g*)))
*<Koordpunkt-g* (if (= "\"\"" *<Koordpunkt-g*)
""
*<Koordpunkt-g*))
(setq *<Koordpunkt-i* (1+ (atoi (setq *<Koordpunkt-z* (:MaxAttValue *<Koordpunkt-g*))))
*<Koordpunkt-z* (strlen *<Koordpunkt-z*)
*<Koordpunkt-i* (cond ((getint (strcat "\nPunktnummer angeben <" (:AddLeadingZeros (itoa *<Koordpunkt-i*) *<Koordpunkt-z*) ">: ")))
(*<Koordpunkt-i*)))
;(setq *<Koordpunkt-z* (cond ((getint (strcat "\nFill up with leading zeros up to <" (itoa *<Koordpunkt-z*) "> place: "))) (*<Koordpunkt-z*))) ; uncomment this line to ask the user
(setq enlast (entlast))
(while (progn
(initget "Undo")
(setq pnt (getpoint (strcat "\nEinfügepunkt angeben für '" (setq txt (strcat *<Koordpunkt-g* (:AddLeadingZeros (itoa *<Koordpunkt-i*) *<Koordpunkt-z*))) "' [Undo] <exit>: "))))
(if (= pnt "Undo")
(progn
(if (equal enlast (entlast))
(alert "Alle eingefügten Punkte gelöscht!")
(progn
(setq enl (entlast))
(command "_.UNDO" 1)
(if (not (equal enl (entlast)))
(setq *<Koordpunkt-i* (1- *<Koordpunkt-i*))))))
(progn
(command "_.-INSERT" "SPI-Koordinatenpunkt" "_none" pnt "1" "1" "" txt "") ;"SPI-Datenextraktionspunkt-CM"
(setq *<Koordpunkt-i* (1+ *<Koordpunkt-i*)))))
) ; end of defun