Typically, the nil result is the last returned value in your code. You can suppress it by adding a princ as the last function of your routine.
This will return the current highest revision level as determined by your layer name pattern. The number 14 is hard-coded to match your current pattern. This number is where your pattern appears to be numbers.
Code:
(defun _getRevisionLevel (doc pattern / rev rev-level rev-layer)
(vlax-for layer (vla-get-layers doc)
(if (wcmatch (strcase (setq rev-layer (vla-get-name layer)))
(strcase pattern)
)
(progn
(if (and (not (vl-catch-all-error-p
(setq rev (vl-catch-all-apply
'atoi
(list (substr rev-layer 14))
)
)
)
)
(> rev rev-level)
)
(setq rev-level rev)
)
)
)
)
rev-level
)
This will take an integer and the desired string length and return the integer as a string with prefixed "0"s. It will return nil if the integer supplied is not able to be converted to string.
Code:
(defun _createRevisionString (level level-length)
(if (not (vl-catch-all-error-p
(setq level (vl-catch-all-apply 'itoa (list level)))
)
)
(while (< (strlen level) level-length)
(setq level (strcat "0" level))
)
(setq level nil)
)
level
)
Taking these two sub-routines, you may be able to piece together the updates to your routine.