Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need script for Widow/Orphan control

Explorer ,
Aug 15, 2024 Aug 15, 2024

Hello. I need a script for structured documents that can find the first and last item element in a sequential list and set them to Keep with Previous. I know this can be controlled through the EDD, but our templates are provided by our customer and we are unfortunately prohibited from editing them. Getting them to fix it is like getting blood out of a turnip. My team wastes a lot of time trying to find widows and orphans and when one slips through, it typically means republishing to PDF from scratch. I need this to be an automated process. Does anyone know of a script that could perform this function for me? If this has already been answered in another thread, I'd be happy to be redirected there. Thanks in advance. 
Matt

TOPICS
Formatting and numbering , Scripting , Structured
423
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 18, 2024 Aug 18, 2024

Hi,
Manually overriding paragraph formatting should not be used in structured documents, as it can lead to confusion in future revisions.
However, if you must do so, the following script might help:

#target framemaker
/*
    Finds the first and last elements in a sequential list and overrides paragraph formatting
*/

var doc = app.ActiveDoc;
var elements = doc.MainFlowInDoc.GetText (Constants.FTI_ElementBegin);

for (var i=0;i<elements.length;i++){
    // Enter the name of a sequential list element defined in your EDD
	if (elements[i].obj.ElementDef.Name == "Seqlist"){
        f_changePgfProps (elements[i].obj.FirstChildElement);
        f_changePgfProps (elements[i].obj.LastChildElement);
    }
}

function f_changePgfProps (ele){
    // Modify the script as needed
    var childEles = ele.GetText (Constants.FTI_ElementBegin);
    for (var i=1;i<childEles.length;i++){
        childEles[i].obj.TextRange.beg.obj.KeepWithPrev = true;
    }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 19, 2024 Sep 19, 2024

Thank you very much for this script. I'm going to try it right away. I understand what you're saying about paragraph overrides possibly leading to confusion, but in this case I think it will work well. I developed a FOSI for a program that used Arbortext for the authoring and set the first and last item elements to keep with previous and it worked beautifully. We never had any widow/orphan issues in the 10 or so years since. I can't wait to give your script a try.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 19, 2024 Sep 19, 2024
LATEST

I gave it a try and it worked great until it hit some nested Seqlists. I should have specified that we have nested Seqlists because most DTDs I've worked with (e.g., 38784) don't allow that. So what ended up happening was the Keep With Previous setting was applied to all list items within the nested lists. Are there some adjustments I could make to this script to compensate for this? Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2024 Aug 19, 2024

Yatani's script is an elegant solution; however, I might be tempted to choose Structure > EDD > Export Element Catalog as EDD. Then set the first and last paragraph rules to keep with next and keep with previous, respectively, for the sequential list element. You could use File > Import > Element Definitions to import this "special" EDD when you are doing your PDF publishing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 19, 2024 Sep 19, 2024

Thanks for the suggestion. I'm going to try the script first only because my organization is not permitted to alter the EDD provided by our customer. Personally, I'd rather do it this way and just not tell anyone outside of my group. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines