this modified Tabnumber.lsp version will give you the option to enter number to reduce from total layout count.
if you need to reset this number, use TabnumberClr command:
; TabNumber function performs the following:
; When run 1st time prompts for Attribute selection,
; its Tag & Block name will be used to
; collect all matching Blocks in the current drawing,
; cycle through all [Layouts] with [Model tab ignored]
; where Blocks are placed and input the following
; 2 fields onto the found matching Attribute:
; First field is layout order # and
; Second field is total # of Layouts
; Fields are used so they will automatically update when Layouts are added or deleted
; as well as when Layouts are moved to a different sequence order
; For example:
; When matching Block Attribute is found the following info will be placed:
; 3 OF 4
; 3 Field represents the Layout is 3rd in order sequence
; 4 Field represents total number of Layouts
; Note: Fieldeval is set to 31 so a save, regen or plot will update the field value
; When run thereafter TabNumber will use Attribute & Block info from object selected on first run
; Use TabNumberClr function
; to clear the first time Attribute & Block selection so a new Attribute selection can be made
; Programmed in response to:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/auto-renaming-page-number-in-layouts/td-p/11689335/jump-to/first-unread-message
; and changed to pick Attribute in response to:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/automatic-current-sheet-numbering-in-the-block-autolips/td-p/11695206
; Modified from:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-auto-page-number-layout-tabs/m-p/10199097#M413381
(princ"\nLoading Function...")(princ)
(defun c:tabnumber (/ _lay2fld _put aec_chkblknam ctab en ed fld num s tabnam) ; aec_blk_name aec_tag_name aec_tabnum_tot
(vl-load-com)
(setvar"fieldeval"31)
; _lay2fld function returns field values of current layout order & total number of layouts
; modified from lay2fld
; Argument:
; n = number to reduce total layout count
; https://forums.augi.com/showthread.php?170740-Getting-the-number-of-a-layout-tab
(defun _lay2fld ( n / doc lay ids id1 id2)
;;------------------------------------;;
;; Tharwat - Date: 03.Dec.2017 ;;
;;------------------------------------;;
; ids function gets given object ids
(defun ids (obj doc / uty)
(if (vlax-method-applicable-p
(setq uty (vla-get-utility doc))
'getobjectidstring
)
(vla-getobjectidstring uty obj :vlax-false)
(itoa (vla-get-objectid obj))
)
) ; defun ids
(setq doc (vla-get-activedocument (vlax-get-acad-object)) ; get current dwg obj
lay (vla-get-layouts doc) ; get all Layouts
id1 (ids (vla-item lay (getvar 'ctab)) doc) ; get current Layout object id
id2 (ids lay doc) ; get total Layout object id
)
; setup the two Field strings
(strcat
"%<\\AcObjProp Object(%<\\_ObjId " id1 ">%).TabOrder>%"
" OF " "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId " id2
">%).Count>%- " (itoa (1+ n)) ">%"
)
) ; defun _lay2fld
; _put function collects given Block's Attributes & finds matching Tag to place Fields value
(defun _put (blk tag val)
; when found matching Attribute Tag name replace with Field string value
(vl-some
'(lambda (x) (and (equal (vla-get-tagstring x) (strcase tag)) (vla-put-textstring x val)))
(vlax-invoke blk 'getattributes) ; get all Attributes within Block returns as a list
)
) ; defun _put
; aec_chkblknam function chks for dynamic block before returns block name
; Argument:
; ent-arg = entity object
; Returns:
; block name
(defun aec_chkblknam (ent-arg / objv)
(setq objv (VLAX-ENAME->VLA-OBJECT ent-arg)) ; convert entity to obj
(if (= (VLAX-GET-PROPERTY objv 'IsDynamicBlock) :VLAX-TRUE) ; chk if dynamic block
(vlax-get-property objv 'EffectiveName)
(cdr (assoc 2 (entget ent-arg)))
)
) ; defun
;; No longer implementing following:
;; Edit below to match with Block name and Attribute Tag name
; (setq
; aec_blk_name "TITLE_BLOCK_INFORMATION_NEW_OCT 19-2010" ; "YOURTITLEBLOCKNAME"
; aec_tag_name "SHEET#" ; "YOURATTRIBUTETAG"
; ) ; setq
;; Implement Select Attribute:
(while (not aec_blk_name)
(setq aec_blk_name (nentsel"\nSelect Attribute Tag To Enter Page Number Fields:" ))
(if
(or
(not aec_blk_name)
(not (equal "ATTRIB" (cdr(assoc 0(setq ed(entget(setq en(car aec_blk_name))))))))
)
(progn ; then did not select Attribute
(setq aec_blk_name nil)
(princ"\nObject Selected is Not an Attribute...")(princ)
)
(progn
(setq aec_tag_name (cdr(assoc 2 ed))) ; get & set global Attribute Tag name
(setq aec_blk_name (aec_chkblknam(cdr(assoc 330 ed)))) ; get & set global Block name including Dynamic
; # to reduce total layout tab count
(if(not aec_tabnum_tot)(setq aec_tabnum_tot 0)) ; set global # to subtract from total Layout quantity
(if (setq num(getint(strcat"\nEnter Number To Subtract from Total Layout Quantity: <"(itoa aec_tabnum_tot)">: ")))
(setq aec_tabnum_tot (abs num))
) ; if
(alert
(strcat
"Running TabNumber on Block Attributes Found in Layouts\n"
"Subtracting Total Layout Quantity by: [" (itoa aec_tabnum_tot) "]\n"
"Block Attributes Found in Model tab are Ignored."
) ; strcat
) ; alert
) ; progn
) ; if
) ; while
(if aec_blk_name
(progn ; Attribute selected
(setq ctab (getvar"ctab")) ; save current Layout
(if (setq s (ssget "_A" (list '(0 . "INSERT") (cons 2 (strcat aec_blk_name ",`*U*")) '(66 . 1)))) ; get all matching Blocks including Dynamic
(progn
(foreach b (mapcar 'cadr (ssnamex s)) ; create list of all entities from selection set & cycle through
(if
(and
(= 'ename (type b)) ; confirm is entity
(setq tabnam(cdr (assoc 410 (entget b)))) ; get Layout name where Block is placed
(/= tabnam "Model") ; ignore Block if placed in Model
)
(progn
(setvar "ctab" tabnam) ; make Layout current
(setq fld (_lay2fld aec_tabnum_tot)) ; get Field value
(_put (vlax-ename->vla-object b) aec_tag_name fld) ; place Field value into Attribute
) ; progn
) ; if
) ; then loop
(if(equal (getvar"ctab") ctab) ; chk if last Layout in loop matches with original
(command"_.Regen") ; then regen to update Fields
(setvar"ctab"ctab) ; else return to original Layout
) ; if
(alert"TabNumber Completed Successfully.\nTo Reselect Another Run Command:\n[TabNumberClr]")
) ; progn
(alert
(strcat"No Matching Blocks Named:\n\t["
aec_blk_name
"]\nWith Attribute Tag Named:\n\t["
aec_tag_name
"]\nFound in Current Drawing."
)
) ; else alert
) ; if Blocks found
) ; progn Attrib selected
) ; if aec_blk_name
(princ)
) ; defun TabNumber
; TabNumberClr function
(defun c:tabnumberclr ()
(setq aec_blk_name nil) ; clear global Block name
(princ"\nTABNUMBER Successfully Cleared.")(princ)
(c:tabnumber) ; run TabNumber function
); defun TabNumberClr
(princ"\n...Loaded Successfully...Enter Command:\n\t[TABNUMBER] to Execute.\n\t[TABNUMBERCLR] to Reselect.")(princ)