Skip to main content
Susan305351693t3o
Inspiring
March 25, 2025
Answered

I'm having a problem with chapters starting back at "1"

  • March 25, 2025
  • 2 replies
  • 1537 views

Hello,

 

I have a subchapter in a book where the subchapters are numbered. It starts at a subchapter, 5.1, with the paragraph style "Heading 1 Start, and the number properties as <$chapnum>.<n=1> :

 

Subsequent subchapters follow the "Heading 1 Continue" style and the number properies as <$chapnum>.<n+> , and it works just fine for 5.2 and 5.3, following the properties for Heading 1 Continue":

 

 

But then, when I try to start a new subchapter, 5.4, it only wants to be 5.1, despite having the exact same paragraph style and properties:

 

 A couple of notes:

1. I have removed all overrides.

2. I am not a programmer. Unless you have text to copy and paste into the code, anything you say will go right over my head 😜.

 

Thank you.

 

 

    Correct answer frameexpert

    Here is a script I always wanted to write. It provides a report of all of your paragraphs that have autonumbering applied. It gives you the actual number (or text), followed by the building blocks. It should help troubleshoot instances where the numbers aren't correct.

     

    To use the script, copy it into a plain text file and save it in a convenient location with a .jsx extension. Open your document or book and choose File > Script > Run and select the script. You should get the Book Error Log with all of your autonumber data. If you look at the entries above where the number resets to 5.1, you should discover the paragraph that is incorrectly resetting the number. If you have trouble figuring it out, save the log file or take a screenshot of the log above the 5.1 paragraph.

     

    To save the Book Error Log, you must unlock it first. Press Esc F l k (l = lower-case L) in sequence to unlock the file. Then you can save it as a regular FrameMaker document.

     

    /* CP-AutonumberReport.jsx Version 0.1b March 25, 2025
    Copyright 2025, Carmen Publishing Inc. All rights reserved.
    
    For information, call 585-729-6746 or email rick@frameexpert.com.
    
    Not to be resold without permission.
    
    Version 0.1b March 25, 2025: First release of the script. 
    */
    
    #target framemaker
    
    var CP_ANR = CP_ANR || {};
    CP_ANR.version = "Version 0.1b March 25, 2025";
    CP_ANR.file = $.fileName;
    
    CP_ANR.main = function () {
        
        var book, doc, markerType, counter;
        
        book = app.ActiveBook;
        if (book.ObjectValid () === 1) {
            CP_ANR.processBook (book);
        }
        else {
            doc = app.ActiveDoc;
            if (doc.ObjectValid () === 1) {
                CP_ANR.processDoc (doc, 0);
            }        
        }
    };
    
    CP_ANR.processDoc = function (doc, bookId) {
    
        var pgf;
        
        // Process all paragraphs in the main flow.
        pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
        while (pgf.ObjectValid () === 1) {
            CP_ANR.processPgf (pgf, doc, bookId);
            pgf = pgf.NextPgfInFlow;
        }
    };
    
    CP_ANR.processBook = function (book) {
        
        var bookComp, doc, regex;
        
        // Regular expression for standard FrameMaker documents.
        regex = /\.fm$/i;
        
        // Loop through all of the components in the book.
        bookComp = book.FirstComponentInBook;
        while (bookComp.ObjectValid () === 1) {
            if (bookComp.ExcludeBookComponent === 0) {
                if (regex.test (bookComp.Name) === true) {
    				// Skip generated files.
    				if (bookComp.BookComponentType === Constants.FV_BK_NOT_GENERATABLE) {
    					// Get the document returned in a JavaScript object.
    					doc = CP_ANR.getDocument (bookComp.Name, undefined, false);
    					if ((doc) && (doc.ObjectValid () === 1)) {
    						book.StatusLine = "Processing " + new File (bookComp.Name).displayName;
    						// Call the function to get the document's autonumber data.
    						CP_ANR.processDoc (doc, book.id)
    						// If the document was opened by the script, save it and close it.
    						if (doc.openedByScript === true) {
    							//doc.SimpleSave (bookComp.Name, false);
    							doc.Close (true);
    						}
    					}
    				}
    			}
            }
            bookComp = bookComp.NextBookComponentInDFSOrder;
        }
    
        // Reset the book status line.
        book.StatusLine = "";
    };
    
    CP_ANR.processPgf = function (pgf, doc, bookId) {
        
        var textList, count, i, msg;
    
        if (pgf.PgfIsAutoNum === 1) {
            msg = pgf.PgfNumber + " " + pgf.AutoNumString;
            msg = CP_ANR.writeBookErrorLog (pgf.id, doc.id, bookId, msg);    
        }
    
        // Get any tables in the paragraph.
        textList = pgf.GetText (Constants.FTI_TblAnchor);
        count = textList.length;
        for (i = 0; i < count; i += 1) {
            // Process the table.
            CP_ANR.processTbl (textList[i].obj, doc, bookId);
        }
    };
    
    CP_ANR.writeBookErrorLog = function (objId, docId, bookId, msg) { 
        
        /// msg = CP_ANR.writeBookErrorLog (objId, docId, bookId, msg);
        
        msg = 'log -b=' + bookId + ' -d=' + docId + ' -o=' + objId + ' --' + msg;
        CallClient ('BookErrorLog', msg);
        
        return msg; // Return for troubleshooting.
    };
    
    CP_ANR.processTbl = function (tbl, doc, bookId) {
        
        var pgf, cell;
        
        // If the title is at the top, process it first.
        if (tbl.TblTitlePosition === Constants.FV_TBL_TITLE_ABOVE) {
            pgf = tbl.FirstPgf;
            while (pgf.ObjectValid () === 1) {
                if (pgf.PgfIsAutoNum === 1) {
                    CP_ANR.processPgf (pgf, doc, bookId);
                }
                pgf = pgf.NextPgfInFlow;
            }
        }
    
        // Process each cell and its paragraphs.
        cell = tbl.FirstRowInTbl.FirstCellInRow;
        while (cell.ObjectValid () === 1) {
            if (cell.CellIsStraddled === 0) {
                pgf = cell.FirstPgf;
                while (pgf.ObjectValid () === 1) {
                    if (pgf.PgfIsAutoNum === 1) {
                        CP_ANR.processPgf (pgf, doc, bookId);
                    }
                    pgf = pgf.NextPgfInFlow;
                }
            }
            cell = cell.NextCellInTbl;
        }
        
        // IF the title is at the bottom, process it last.
        if (tbl.TblTitlePosition === Constants.FV_TBL_TITLE_BELOW) {
            while (pgf.ObjectValid () === 1) {
                if (pgf.PgfIsAutoNum === 1) {
                    CP_ANR.processPgf (pgf, doc, bookId);
                }
                pgf = pgf.NextPgfInFlow;
            }
        } 
    };
    
    CP_ANR.getDocument = function (filename, structuredApplication, visible) {
        
        var doc;
        
        // See if the document is already open.
        doc = CP_ANR.docIsOpen (filename);
        if ((doc) && (doc.ObjectValid () === 1)) {
            return doc;
        } 
        else {
            // The document is not already open, so open it.
            return CP_ANR.openDocOrBook (filename, structuredApplication, visible);
        }
    };
    
    CP_ANR.docIsOpen = function (filename) {
        
        var file, name, doc;
        
        // Make a File object from the file name.
        file = new File (filename);
        // Uppercase the filename for easy comparison.
        name = file.fullName.toUpperCase ();
    
        // Loop through the open documents in the session.
        doc = app.FirstOpenDoc;
        while (doc.ObjectValid () === 1) {
            // Compare the document’s name with the one we are looking for.
            if (new File (doc.Name).fullName.toUpperCase () === name) {
                // The document we are looking for is open.
                doc.openedByScript = false;
                return doc;
            }
            doc = doc.NextOpenDocInSession;
        }
    };
    
    CP_ANR.openDocOrBook = function (filename, structuredApplication, visible) {
        
        var i = 0, docOrBook = 0, openProps, returnProps;
    
        // Get default property list for opening documents.
        openProps = GetOpenDefaultParams ();
        // Get a property list to return any error messages.
        returnProps = new PropVals ();
    
        // Set specific open property values to open the document.
        i = GetPropIndex (openProps,Constants.FS_AlertUserAboutFailure);
        openProps[i].propVal.ival=false;
        i = GetPropIndex (openProps,Constants.FS_MakeVisible);
        openProps[i].propVal.ival=visible;
        i = GetPropIndex (openProps,Constants.FS_FileIsOldVersion);
        openProps[i].propVal.ival=Constants.FV_DoOK;
        i = GetPropIndex (openProps,Constants.FS_FileIsInUse);
        openProps[i].propVal.ival=Constants.FV_ResetLockAndContinue;
        i = GetPropIndex (openProps,Constants.FS_FontChangedMetric);
        openProps[i].propVal.ival=Constants.FV_DoOK;
        i = GetPropIndex (openProps,Constants.FS_FontNotFoundInCatalog);
        openProps[i].propVal.ival=Constants.FV_DoOK;
        i = GetPropIndex (openProps,Constants.FS_FontNotFoundInDoc);
        openProps[i].propVal.ival=Constants.FV_DoOK;
        i = GetPropIndex (openProps,Constants.FS_RefFileNotFound);
        openProps[i].propVal.ival=Constants.FV_AllowAllRefFilesUnFindable;
        i = GetPropIndex (openProps,Constants.FS_UseRecoverFile);
        openProps[i].propVal.ival=Constants.FV_DoNo;
        if (structuredApplication !== undefined) {
            i = GetPropIndex (openProps,Constants.FS_StructuredOpenApplication);
            openProps[i].propVal.sval=structuredApplication;
        }
    
        // Attempt to open the document.
        docOrBook = Open (filename,openProps,returnProps);
    
        if (docOrBook.ObjectValid () === 1) {
            // Add a property to the document or book, indicating that the script opened it.
            docOrBook.openedByScript = true;
        }
        else {
            // If the document can't be open, print the errors to the Console.
            PrintOpenStatus (returnProps);
            Console ("\r" + filename);
        }
    
        return docOrBook; // Return the document or book object.
    };
    
    CP_ANR.main ();
    

    Susan and I figured out the problem. There were two separate sets of paragraph formats without series labels (including the heading paragraphs) and they caused the numbers to restart. I showed her how to use series labels to keep numbering paragraphs independent of each other.

     

    Also, I updated my script to ignore autonumbers without numbering building blocks; for example, bullets and text-only autonumbers. Here is the updated script.

    /* CP-AutonumberReport.jsx Version 0.2b March 28, 2025
    Copyright 2025, Carmen Publishing Inc. All rights reserved.
    
    For information, call 585-729-6746 or email rick@frameexpert.com.
    
    Not to be resold without permission.
    
    Version 0.2b March 28, 2025: Non-numbered autonumbered paragraphs are skipped. 
    Version 0.1b March 25, 2025: First release of the script. 
    */
    
    #target framemaker
    
    var CP_ANR = CP_ANR || {};
    CP_ANR.version = "Version 0.2b March 28, 2025";
    CP_ANR.file = $.fileName;
    
    CP_ANR.main = function () {
        
        var book, doc;
        
        book = app.ActiveBook;
        if (book.ObjectValid () === 1) {
            CP_ANR.processBook (book);
        }
        else {
            doc = app.ActiveDoc;
            if (doc.ObjectValid () === 1) {
                CP_ANR.processDoc (doc, 0);
            }        
        }
    };
    
    CP_ANR.processDoc = function (doc, bookId) {
    
        var pgf;
        
        // Process all paragraphs in the main flow.
        pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
        while (pgf.ObjectValid () === 1) {
            CP_ANR.processPgf (pgf, doc, bookId);
            pgf = pgf.NextPgfInFlow;
        }
    };
    
    CP_ANR.processBook = function (book) {
        
        var bookComp, doc, regex;
        
        // Regular expression for standard FrameMaker documents.
        regex = /\.fm$/i;
        
        // Loop through all of the components in the book.
        bookComp = book.FirstComponentInBook;
        while (bookComp.ObjectValid () === 1) {
            if (bookComp.ExcludeBookComponent === 0) {
                if (regex.test (bookComp.Name) === true) {
    				// Skip generated files.
    				if (bookComp.BookComponentType === Constants.FV_BK_NOT_GENERATABLE) {
    					// Get the document returned in a JavaScript object.
    					doc = CP_ANR.getDocument (bookComp.Name, undefined, false);
    					if ((doc) && (doc.ObjectValid () === 1)) {
    						book.StatusLine = "Processing " + new File (bookComp.Name).displayName;
    						// Call the function to get the document's autonumber data.
    						CP_ANR.processDoc (doc, book.id)
    						// If the document was opened by the script, save it and close it.
    						if (doc.openedByScript === true) {
    							//doc.SimpleSave (bookComp.Name, false);
    							doc.Close (true);
    						}
    					}
    				}
    			}
            }
            bookComp = bookComp.NextBookComponentInDFSOrder;
        }
    
        // Reset the book status line.
        book.StatusLine = "";
    };
    
    CP_ANR.processPgf = function (pgf, doc, bookId) {
        
        var textList, count, i, msg;
    
        if (pgf.PgfIsAutoNum === 1) {
            // Make sure there are actual building blocks (skip bullets, text-only, etc.).
            if (/</.test (pgf.AutoNumString) === true) {
                msg = pgf.PgfNumber + "  " + pgf.AutoNumString + "  [" + pgf.Name + "]";
                msg = CP_ANR.writeBookErrorLog (pgf.id, doc.id, bookId, msg);    
            }
        }
    
        // Get any tables in the paragraph.
        textList = pgf.GetText (Constants.FTI_TblAnchor);
        count = textList.length;
        for (i = 0; i < count; i += 1) {
            // Process the table.
            CP_ANR.processTbl (textList[i].obj, doc, bookId);
        }
    };
    
    CP_ANR.writeBookErrorLog = function (objId, docId, bookId, msg) { 
        
        /// msg = CP_ANR.writeBookErrorLog (objId, docId, bookId, msg);
        
        msg = 'log -b=' + bookId + ' -d=' + docId + ' -o=' + objId + ' --' + msg;
        CallClient ('BookErrorLog', msg);
        
        return msg; // Return for troubleshooting.
    };
    
    CP_ANR.processTbl = function (tbl, doc, bookId) {
        
        var pgf, cell;
        
        // If the title is at the top, process it first.
        if (tbl.TblTitlePosition === Constants.FV_TBL_TITLE_ABOVE) {
            pgf = tbl.FirstPgf;
            while (pgf.ObjectValid () === 1) {
                if (pgf.PgfIsAutoNum === 1) {
                    CP_ANR.processPgf (pgf, doc, bookId);
                }
                pgf = pgf.NextPgfInFlow;
            }
        }
    
        // Process each cell and its paragraphs.
        cell = tbl.FirstRowInTbl.FirstCellInRow;
        while (cell.ObjectValid () === 1) {
            if (cell.CellIsStraddled === 0) {
                pgf = cell.FirstPgf;
                while (pgf.ObjectValid () === 1) {
                    if (pgf.PgfIsAutoNum === 1) {
                        CP_ANR.processPgf (pgf, doc, bookId);
                    }
                    pgf = pgf.NextPgfInFlow;
                }
            }
            cell = cell.NextCellInTbl;
        }
        
        // IF the title is at the bottom, process it last.
        if (tbl.TblTitlePosition === Constants.FV_TBL_TITLE_BELOW) {
            while (pgf.ObjectValid () === 1) {
                if (pgf.PgfIsAutoNum === 1) {
                    CP_ANR.processPgf (pgf, doc, bookId);
                }
                pgf = pgf.NextPgfInFlow;
            }
        } 
    };
    
    CP_ANR.getDocument = function (filename, structuredApplication, visible) {
        
        var doc;
        
        // See if the document is already open.
        doc = CP_ANR.docIsOpen (filename);
        if ((doc) && (doc.ObjectValid () === 1)) {
            return doc;
        } 
        else {
            // The document is not already open, so open it.
            return CP_ANR.openDocOrBook (filename, structuredApplication, visible);
        }
    };
    
    CP_ANR.docIsOpen = function (filename) {
        
        var file, name, doc;
        
        // Make a File object from the file name.
        file = new File (filename);
        // Uppercase the filename for easy comparison.
        name = file.fullName.toUpperCase ();
    
        // Loop through the open documents in the session.
        doc = app.FirstOpenDoc;
        while (doc.ObjectValid () === 1) {
            // Compare the document’s name with the one we are looking for.
            if (new File (doc.Name).fullName.toUpperCase () === name) {
                // The document we are looking for is open.
                doc.openedByScript = false;
                return doc;
            }
            doc = doc.NextOpenDocInSession;
        }
    };
    
    CP_ANR.openDocOrBook = function (filename, structuredApplication, visible) {
        
        var i = 0, docOrBook = 0, openProps, returnProps;
    
        // Get default property list for opening documents.
        openProps = GetOpenDefaultParams ();
        // Get a property list to return any error messages.
        returnProps = new PropVals ();
    
        // Set specific open property values to open the document.
        i = GetPropIndex (openProps,Constants.FS_AlertUserAboutFailure);
        openProps[i].propVal.ival=false;
        i = GetPropIndex (openProps,Constants.FS_MakeVisible);
        openProps[i].propVal.ival=visible;
        i = GetPropIndex (openProps,Constants.FS_FileIsOldVersion);
        openProps[i].propVal.ival=Constants.FV_DoOK;
        i = GetPropIndex (openProps,Constants.FS_FileIsInUse);
        openProps[i].propVal.ival=Constants.FV_ResetLockAndContinue;
        i = GetPropIndex (openProps,Constants.FS_FontChangedMetric);
        openProps[i].propVal.ival=Constants.FV_DoOK;
        i = GetPropIndex (openProps,Constants.FS_FontNotFoundInCatalog);
        openProps[i].propVal.ival=Constants.FV_DoOK;
        i = GetPropIndex (openProps,Constants.FS_FontNotFoundInDoc);
        openProps[i].propVal.ival=Constants.FV_DoOK;
        i = GetPropIndex (openProps,Constants.FS_RefFileNotFound);
        openProps[i].propVal.ival=Constants.FV_AllowAllRefFilesUnFindable;
        i = GetPropIndex (openProps,Constants.FS_UseRecoverFile);
        openProps[i].propVal.ival=Constants.FV_DoNo;
        if (structuredApplication !== undefined) {
            i = GetPropIndex (openProps,Constants.FS_StructuredOpenApplication);
            openProps[i].propVal.sval=structuredApplication;
        }
    
        // Attempt to open the document.
        docOrBook = Open (filename,openProps,returnProps);
    
        if (docOrBook.ObjectValid () === 1) {
            // Add a property to the document or book, indicating that the script opened it.
            docOrBook.openedByScript = true;
        }
        else {
            // If the document can't be open, print the errors to the Console.
            PrintOpenStatus (returnProps);
            Console ("\r" + filename);
        }
    
        return docOrBook; // Return the document or book object.
    };
    
    CP_ANR.main ();
    

    2 replies

    frameexpert
    Community Expert
    Community Expert
    March 26, 2025

    Hi Susan, You need to set the numbering at the book level instead of the document level. Click on one or more components in the book, right-click and choose Numbering. Set the desired numbering properties there and update the book. Dismiss any "Inconsistent numbering" dialog boxes and you should be all set.

    frameexpert
    Community Expert
    Community Expert
    March 26, 2025

    You might find this series of short videos helpful to understand FrameMaker pagination and numbering:

    https://youtu.be/AiI1DOoA6Ug?si=TB2sa98B-RuFrpn8

    Bob_Niland
    Community Expert
    Community Expert
    March 26, 2025

    It appears that you aren't using a Series Label for the numbering.
    This might appear as the H: in a
    Paragaph Format /Numbering\
    Format: [ H:‹$chapnum›.‹n=1› ]

     

    If the case, various stray numbered paras of other types might be resetting the default counter.

    …which is one reason why the Series Label feature exists.

     

    Also, check the Numbering properties from the Book menu for each chapter (it's a right-click option), plus within each chapter (Format🞃Document🞂Numbering…), esp. the chapter that's resetting to 1.